Advertisement
pleasedontcode

Time Controller rev_11

Feb 11th, 2024
37
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: Time Controller
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-02-11 13:31:00
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* lcd_LCD1602I2C_I2C line one: 1CZAS,   second line: */
  21.     /* 2CZAS  1CZAS is the time clock, set the start */
  22.     /* value: 7:00  2CZAS is the time clock, set the */
  23.     /* start value: 2:00  2_PushButton held down starts */
  24.     /* subtracting 0:01 value from 2CZAS every 1 second */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Subtracts the value 0:01 from 1CZAS every 1 second */
  27.     /* from startup.  Releasing the 2_PushButton restores */
  28.     /* the initial 2CZAS value.  The minimum value of */
  29.     /* 1CZAS and 2CZAS is 0:00.  Activate the */
  30.     /* b_ActiveBuzzer_output when the minimum value is */
  31.     /* 0:00 */
  32. /****** END SYSTEM REQUIREMENTS *****/
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <Wire.h>
  36. #include <EasyButton.h>
  37. #include <LiquidCrystal_I2C.h>
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup();
  41. void loop();
  42. void updateCzasClock();
  43. void updatePushButtons();
  44. void updateOutputs();
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t PushButton_PIN_D5 = 5;
  48. const uint8_t PushButton_PIN_D2 = 2;
  49.  
  50. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  51. const uint8_t ActiveBuzzer_output_PIN_D4 = 4;
  52.  
  53. /***** DEFINITION OF I2C PINS *****/
  54. const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  55. const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  56. const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  57.  
  58. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  59. bool ActiveBuzzer_output_PIN_D4_rawData = 0;
  60.  
  61. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  62. int czas1Hour = 7;
  63. int czas1Minute = 0;
  64. int czas2Hour = 2;
  65. int czas2Minute = 0;
  66. bool subtractCzas2 = false;
  67. const int BUZZER_MINUTE = 0;
  68.  
  69. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  70. EasyButton button(PushButton_PIN_D5);
  71. EasyButton button2(PushButton_PIN_D2);
  72. LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  73.  
  74. void onPressedForDuration()
  75. {
  76.   // Callback function to be called when the button is pressed for the given duration.
  77.   subtractCzas2 = true;
  78. }
  79.  
  80. void setup()
  81. {
  82.   // put your setup code here, to run once:
  83.   pinMode(PushButton_PIN_D5, INPUT_PULLUP);
  84.   pinMode(PushButton_PIN_D2, INPUT_PULLUP);
  85.  
  86.   pinMode(ActiveBuzzer_output_PIN_D4, OUTPUT);
  87.  
  88.   button.begin();
  89.   button.onPressedFor(2000, onPressedForDuration);
  90.  
  91.   button2.begin();
  92.  
  93.   lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  94.   lcd.setBacklight(HIGH); // Turn on the backlight
  95.   lcd.clear(); // Clear the LCD screen
  96.   lcd.setCursor(0, 0);
  97.   lcd.print("1CZAS:     7:00");
  98.   lcd.setCursor(0, 1);
  99.   lcd.print("2CZAS:     2:00");
  100. }
  101.  
  102. void loop()
  103. {
  104.   // put your main code here, to run repeatedly:
  105.   updateCzasClock();
  106.   updatePushButtons();
  107.   updateOutputs();
  108. }
  109.  
  110. void updateCzasClock()
  111. {
  112.   if (subtractCzas2)
  113.   {
  114.     if (czas2Minute > BUZZER_MINUTE)
  115.     {
  116.       czas2Minute--;
  117.     }
  118.     else
  119.     {
  120.       if (czas2Hour > 0)
  121.       {
  122.         czas2Hour--;
  123.         czas2Minute = 59;
  124.       }
  125.       else
  126.       {
  127.         if (czas1Minute > BUZZER_MINUTE)
  128.         {
  129.           czas1Minute--;
  130.         }
  131.         else
  132.         {
  133.           if (czas1Hour > 0)
  134.           {
  135.             czas1Hour--;
  136.             czas1Minute = 59;
  137.           }
  138.           else
  139.           {
  140.             digitalWrite(ActiveBuzzer_output_PIN_D4, HIGH);
  141.           }
  142.         }
  143.       }
  144.     }
  145.   }
  146. }
  147.  
  148. void updatePushButtons()
  149. {
  150.   button.read();
  151.   button2.read();
  152.  
  153.   if (button.isReleased())
  154.   {
  155.     subtractCzas2 = false;
  156.   }
  157.  
  158.   if (button2.isPressed())
  159.   {
  160.     if (czas2Minute > BUZZER_MINUTE || czas2Hour > 0)
  161.     {
  162.       czas2Minute--;
  163.       delay(1000);
  164.     }
  165.   }
  166. }
  167.  
  168. void updateOutputs()
  169. {
  170.   digitalWrite(ActiveBuzzer_output_PIN_D4, ActiveBuzzer_output_PIN_D4_rawData);
  171.  
  172.   lcd.setCursor(7, 0);
  173.   lcd.print(czas1Hour < 10 ? "0" : "");
  174.   lcd.print(czas1Hour);
  175.   lcd.print(":");
  176.   lcd.print(czas1Minute < 10 ? "0" : "");
  177.   lcd.print(czas1Minute);
  178.  
  179.   lcd.setCursor(7, 1);
  180.   lcd.print(czas2Hour < 10 ? "0" : "");
  181.   lcd.print(czas2Hour);
  182.   lcd.print(":");
  183.   lcd.print(czas2Minute < 10 ? "0" : "");
  184.   lcd.print(czas2Minute);
  185. }
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement