Advertisement
pleasedontcode

"Digital Control" rev_06

Feb 4th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Digital Control"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-02-04 14:53:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* On LCD1602_LCD1602I2C_I2C display   on the first */
  21.     /* line: CZERWONY "+resultC"  on the second line: */
  22.     /* ZOLTY "+resultZ"  the initial value of resultC and */
  23.     /* resultZ is 10000. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* Holding down the czerwonyP_PushButton subtracts */
  26.     /* from the resultC.  Holding down the */
  27.     /* zielonyP_PushButton subtracts from the resultZ. */
  28.     /* Holding time subtracts value:  1 second subtracts */
  29.     /* randomly 10 to 40, until the button is released. */
  30. /****** END SYSTEM REQUIREMENTS *****/
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <Wire.h>
  34. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  35. #include <LiquidCrystal_I2C.h>    //https://github.com/marcoschwartz/LiquidCrystal_I2C
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40. void updateOutputs(void);
  41. void onPressedForDuration(void);
  42.  
  43. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  44. const uint8_t PUSHBUTTON_PIN_D2 = 2;
  45.  
  46. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  47. const uint8_t L1_LED_PIN_D3 = 3;
  48. const uint8_t B_ACTIVEBUZZER_OUTPUT_PIN_D4 = 4;
  49.  
  50. /***** DEFINITION OF I2C PINS *****/
  51. const uint8_t LCD_I2C_PIN_SDA_A4 = A4;
  52. const uint8_t LCD_I2C_PIN_SCL_A5 = A5;
  53. const uint8_t LCD_I2C_SLAVE_ADDRESS = 0x27;
  54.  
  55. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  56. /***** used to store raw data *****/
  57. bool L1_LED_PIN_D3_rawData = false;
  58. bool B_ACTIVEBUZZER_OUTPUT_PIN_D4_rawData = false;
  59.  
  60. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  61. /***** used to store data after characteristic curve transformation *****/
  62. int resultC = 10000;
  63. int resultZ = 10000;
  64.  
  65. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  66. EasyButton pushButton(PUSHBUTTON_PIN_D2);
  67. LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LiquidCrystal_I2C object
  68.  
  69. void setup()
  70. {
  71.     // put your setup code here, to run once:
  72.     lcd.begin(20, 4); // Initialize the LCD
  73.     lcd.backlight();
  74.  
  75.     pinMode(PUSHBUTTON_PIN_D2, INPUT_PULLUP);
  76.     pinMode(L1_LED_PIN_D3, OUTPUT);
  77.     pinMode(B_ACTIVEBUZZER_OUTPUT_PIN_D4, OUTPUT);
  78.  
  79.     pushButton.begin();
  80.     pushButton.onPressedFor(2000, onPressedForDuration);
  81. }
  82.  
  83. void loop()
  84. {
  85.     // put your main code here, to run repeatedly:
  86.     pushButton.read();
  87.     updateOutputs(); // Refresh output data
  88.  
  89.     // Display values on LCD
  90.     lcd.setCursor(0, 0);
  91.     lcd.print("CZERWONY ");
  92.     lcd.print(resultC);
  93.  
  94.     lcd.setCursor(0, 1);
  95.     lcd.print("ZOLTY ");
  96.     lcd.print(resultZ);
  97. }
  98.  
  99. void updateOutputs()
  100. {
  101.     digitalWrite(L1_LED_PIN_D3, L1_LED_PIN_D3_rawData);
  102.     digitalWrite(B_ACTIVEBUZZER_OUTPUT_PIN_D4, B_ACTIVEBUZZER_OUTPUT_PIN_D4_rawData);
  103. }
  104.  
  105. void onPressedForDuration()
  106. {
  107.     // Subtract from resultC
  108.     while (pushButton.isPressed())
  109.     {
  110.         resultC--;
  111.         delay(random(1000, 4000)); // Random delay between 1 and 4 seconds
  112.     }
  113.  
  114.     // Subtract from resultZ
  115.     while (pushButton.isReleased())
  116.     {
  117.         resultZ--;
  118.         delay(random(1000, 4000)); // Random delay between 1 and 4 seconds
  119.     }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement