Advertisement
pleasedontcode

"Interactive Clock" rev_10

Feb 11th, 2024
36
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: "Interactive Clock"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-02-11 13:23:34
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* - lcd_LCD1602I2C_I2C line one: 1CZAS,   second */
  21.     /* line: 2CZAS  - 1CZAS is the time clock, set the */
  22.     /* start value: 7:00  - 2CZAS is the time clock, set */
  23.     /* the start value: 2:00  - 2_PushButton held down */
  24.     /* starts subtracting 0:01 value from 2CZAS every 1 */
  25.     /* second */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27.     /* - Subtract the value 0:01 from 1CZAS every 1 */
  28.     /* second.  - 2_PushButton released restores the */
  29.     /* initial value of 2CZAS  - The minimum value of */
  30.     /* 1CZAS and 2CZAS is 0:00  - Activate */
  31.     /* b_ActiveBuzzer_output when the minimum value is */
  32.     /* 0:00 */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /****** DEFINITION OF LIBRARIES *****/
  36. #include <Wire.h>
  37. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  38. #include <LiquidCrystal_I2C.h>    //https://github.com/marcoschwartz/LiquidCrystal_I2C
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void updateClock(void);
  44. void updateOutputs(void);
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t PushButton_PIN_D5 = 5;
  48.  
  49. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  50. const uint8_t ActiveBuzzer_output_PIN_D4 = 4;
  51.  
  52. /***** DEFINITION OF I2C PINS *****/
  53. const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  54. const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  55. const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;
  56.  
  57. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  58. /***** used to store raw data *****/
  59. bool ActiveBuzzer_output_PIN_D4_rawData = 0;
  60.  
  61. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  62. /***** used to store data after characteristic curve transformation *****/
  63. float ActiveBuzzer_output_PIN_D4_phyData = 0.0;
  64.  
  65. /***** DEFINITION OF CLOCK VARIABLES *****/
  66. int hours = 7;
  67. int minutes = 0;
  68.  
  69. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  70. EasyButton button(PushButton_PIN_D5);
  71. LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initializing LiquidCrystal_I2C object with I2C address and screen size
  72.  
  73. void setup(void)
  74. {
  75.     // put your setup code here, to run once:
  76.  
  77.     button.begin();
  78.     pinMode(ActiveBuzzer_output_PIN_D4, OUTPUT);
  79.  
  80.     lcd.begin(20, 4); // Initializing the LCD module with the screen size
  81.  
  82.     lcd.setCursor(0, 0);
  83.     lcd.print("7:00");
  84.  
  85.     lcd.setCursor(0, 1);
  86.     lcd.print("2:00");
  87. }
  88.  
  89. void loop(void)
  90. {
  91.     // put your main code here, to run repeatedly:
  92.  
  93.     button.read();
  94.  
  95.     if (button.wasReleased()) {
  96.         // Reset the clock to initial values
  97.         hours = 7;
  98.         minutes = 0;
  99.     }
  100.  
  101.     if (button.pressedFor(1000)) {
  102.         // Subtract 1 minute from the second clock
  103.         minutes--;
  104.         if (minutes < 0) {
  105.             minutes = 59;
  106.             hours--;
  107.             if (hours < 0) {
  108.                 hours = 0;
  109.             }
  110.         }
  111.     }
  112.  
  113.     updateClock();
  114.     updateOutputs(); // Refresh output data
  115. }
  116.  
  117. void updateClock() {
  118.     lcd.setCursor(0, 0);
  119.     if (hours < 10) {
  120.         lcd.print("0"); // Add leading zero if hours less than 10
  121.     }
  122.     lcd.print(hours);
  123.     lcd.print(":");
  124.     if (minutes < 10) {
  125.         lcd.print("0"); // Add leading zero if minutes less than 10
  126.     }
  127.     lcd.print(minutes);
  128. }
  129.  
  130. void updateOutputs() {
  131.     if (hours == 0 && minutes == 0) {
  132.         ActiveBuzzer_output_PIN_D4_rawData = 1;
  133.     }
  134.     else {
  135.         ActiveBuzzer_output_PIN_D4_rawData = 0;
  136.     }
  137.  
  138.     digitalWrite(ActiveBuzzer_output_PIN_D4, ActiveBuzzer_output_PIN_D4_rawData);
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement