Advertisement
pleasedontcode

Digital Control rev_07

Feb 11th, 2024
39
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-11 12:37:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* lcd_LCD1602I2C_I2C line one: 1CZAS,   second line: */
  21.     /* 2CZAS  1_PushButton when pressed starts */
  22.     /* subtracting 0:01 value from 1CZAS every 1 second. */
  23.     /* 2_PushButton held down starts subtracting the */
  24.     /* value 0:01 from 2CZAS every 1 second. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* 1CZAS is the time clock, set the start value: 7:00 */
  27.     /* 2CZAS is the time clock, set the start value: 2:00 */
  28.     /* 2_PushButton released restores the initial value */
  29.     /* of 2CZAS */
  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); // Function to update the output data
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t PUSHBUTTON_PIN_D2 = 2;
  44. const uint8_t PUSHBUTTON_PIN_D5 = 5;
  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; // Replace with the correct I2C address of your LCD module
  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. float l1_LED_PIN_D3_phyData = 0.0;
  63. float b_ActiveBuzzer_output_PIN_D4_phyData = 0.0;
  64.  
  65. /***** DEFINITION OF SYSTEM VARIABLES *****/
  66. bool button1_pressed = false;
  67. bool button2_pressed = false;
  68. uint8_t czas1_minutes = 7;
  69. uint8_t czas1_seconds = 0;
  70. uint8_t czas2_minutes = 2;
  71. uint8_t czas2_seconds = 0;
  72.  
  73. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  74. EasyButton button1(PUSHBUTTON_PIN_D2);
  75. EasyButton button2(PUSHBUTTON_PIN_D5);
  76. LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 16, 2);  // Change the columns and rows according to your LCD module
  77.  
  78. void setup(void)
  79. {
  80.     // put your setup code here, to run once:
  81.     pinMode(PUSHBUTTON_PIN_D2, INPUT_PULLUP);
  82.     pinMode(PUSHBUTTON_PIN_D5, INPUT_PULLUP);
  83.     pinMode(L1_LED_PIN_D3, OUTPUT);
  84.     pinMode(B_ACTIVEBUZZER_OUTPUT_PIN_D4, OUTPUT);
  85.     lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  86.     lcd.backlight(); // Turn on the LCD backlight
  87. }
  88.  
  89. void loop(void)
  90. {
  91.     // put your main code here, to run repeatedly:
  92.     button1.read();
  93.     button2.read();
  94.  
  95.     // Check if button 1 was pressed
  96.     if (button1.wasPressed())
  97.     {
  98.         czas1_seconds--;
  99.         if (czas1_seconds == 255) // Check for underflow
  100.         {
  101.             czas1_seconds = 59;
  102.             czas1_minutes--;
  103.             if (czas1_minutes == 255) // Check for underflow
  104.             {
  105.                 // Restore initial value
  106.                 czas1_minutes = 7;
  107.                 czas1_seconds = 0;
  108.             }
  109.         }
  110.     }
  111.  
  112.     // Check if button 2 was held down
  113.     if (button2.isPressed())
  114.     {
  115.         czas2_seconds--;
  116.         if (czas2_seconds == 255) // Check for underflow
  117.         {
  118.             czas2_seconds = 59;
  119.             czas2_minutes--;
  120.             if (czas2_minutes == 255) // Check for underflow
  121.             {
  122.                 // Restore initial value
  123.                 czas2_minutes = 2;
  124.                 czas2_seconds = 0;
  125.             }
  126.         }
  127.     }
  128.  
  129.     // Check if button 2 was released
  130.     if (button2.wasReleased())
  131.     {
  132.         // Restore initial value
  133.         czas2_minutes = 2;
  134.         czas2_seconds = 0;
  135.     }
  136.  
  137.     // Display the time on the LCD
  138.     lcd.setCursor(0, 0);
  139.     lcd.print("1CZAS: ");
  140.     lcd.print(czas1_minutes);
  141.     lcd.print(":");
  142.     if (czas1_seconds < 10)
  143.     {
  144.         lcd.print("0");
  145.     }
  146.     lcd.print(czas1_seconds);
  147.  
  148.     lcd.setCursor(0, 1);
  149.     lcd.print("2CZAS: ");
  150.     lcd.print(czas2_minutes);
  151.     lcd.print(":");
  152.     if (czas2_seconds < 10)
  153.     {
  154.         lcd.print("0");
  155.     }
  156.     lcd.print(czas2_seconds);
  157.  
  158.     updateOutputs(); // Refresh output data
  159.     delay(1000); // Delay for 1 second
  160. }
  161.  
  162. void updateOutputs(void)
  163. {
  164.     digitalWrite(L1_LED_PIN_D3, l1_LED_PIN_D3_rawData);
  165.     digitalWrite(B_ACTIVEBUZZER_OUTPUT_PIN_D4, b_ActiveBuzzer_output_PIN_D4_rawData);
  166. }
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement