Advertisement
pseud0_

Untitled

Sep 11th, 2022
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
  3.  
  4. #include "Countimer.h"
  5. Countimer timer;
  6.  
  7. #include <Button.h>
  8.  
  9. #include <EEPROM.h>
  10.  
  11. Button startStopBtn(16);
  12. Button minutesBtn(17);
  13. Button secondsBtn(18);
  14.  
  15. const int backlight = 9;
  16. const int bell = 15;
  17.  
  18. int startHours = 0;
  19. int startMinutes = 0;
  20. int startSeconds = 0;
  21.  
  22. bool settingsMode = false;
  23.  
  24. int bellMillis = 0;
  25. long bellStartMillis;
  26.  
  27.  
  28. void setup() {
  29.  
  30.   startStopBtn.begin();
  31.   minutesBtn.begin();
  32.   secondsBtn.begin();
  33.  
  34.   pinMode(backlight, OUTPUT);
  35.   pinMode(bell, OUTPUT);
  36.  
  37.   lcd.begin(16, 2);
  38.   digitalWrite(backlight, HIGH);
  39.   lcd.setCursor(0, 0);
  40.   lcd.print(F("World's Loudest"));
  41.   lcd.setCursor(1, 1);
  42.   lcd.print(F("Kitchen Timer"));
  43.   delay(3000);
  44.  
  45.   bellMillis = (EEPROM.read(0) * 10);
  46. }
  47.  
  48. void onComplete() {
  49.   //activate bell
  50.   //reset or stop timer
  51.   digitalWrite(bell, HIGH);
  52.   delay(bellMillis);
  53.   digitalWrite(bell, LOW);
  54. }
  55.  
  56. void loop() {
  57.   timer.run();
  58.  
  59.   if (timer.isCounterCompleted() == false && !timer.isStopped() == false) {//timer.isCounterRunning()
  60.     if (settingsMode) {
  61.       if(minutesBtn.pressed()) {
  62.         bellMillis = bellMillis + 100;
  63.       }
  64.  
  65.       if(secondsBtn.pressed()) {
  66.         bellMillis = bellMillis + 10;
  67.       }
  68.  
  69.       if(minutesBtn.pressed() && secondsBtn.pressed()) {
  70.         bellMillis = 10;
  71.       }
  72.       lcd.clear();
  73.       lcd.setCursor(0, 0);
  74.       lcd.print(F("Bell Time"));
  75.       lcd.setCursor(0, 1);
  76.       lcd.print(bellMillis);
  77.       if(startStopBtn.pressed()) {
  78.         //save bellMillis to EEPROM
  79.         EEPROM.update(0, (bellMillis / 10));
  80.         settingsMode = false;
  81.       }
  82.     } else {
  83.       if (minutesBtn.pressed()) {
  84.         startMinutes++;
  85.       }
  86.  
  87.       if (secondsBtn.pressed()) {
  88.         startSeconds++;
  89.       }
  90.  
  91.       if (startMinutes > 60) {
  92.         startMinutes = 0;
  93.       }
  94.  
  95.       if (startSeconds >= 60) {
  96.         startSeconds = 0;
  97.       }
  98.  
  99.       if (minutesBtn.pressed() && secondsBtn.pressed()) {
  100.         startHours = 0;
  101.         startMinutes = 0;
  102.         startSeconds = 0;
  103.       }
  104.       lcd.clear();
  105.       lcd.setCursor(0, 0);
  106.       lcd.print(F("TIMER"));
  107.       lcd.setCursor(0, 1);
  108.       lcd.print(startHours);
  109.       lcd.print(":");
  110.       lcd.print(startMinutes);
  111.       lcd.print(":");
  112.       lcd.print(startSeconds);
  113.       //if startStopBtn is held down, settingsMode = TRUE
  114.       if (startStopBtn.pressed()) {
  115.         timer.setCounter(startHours, startMinutes, startSeconds, timer.COUNT_DOWN, onComplete);
  116.         timer.start();
  117.       }
  118.     }
  119.   }
  120.   if (!timer.isStopped()) {//timer.isCounterRunning()
  121.    
  122.     if (startStopBtn.pressed()){
  123.       timer.pause();
  124.     }
  125.  
  126.     if (minutesBtn.pressed() && secondsBtn.pressed()) {
  127.       startHours = 0;
  128.       startMinutes = 0;
  129.       startSeconds = 0;
  130.       timer.stop();
  131.     }
  132.  
  133.     lcd.clear();
  134.     lcd.setCursor(0, 0);
  135.     lcd.print(F("Timing"));
  136.     lcd.setCursor(0, 1);
  137.     lcd.print(timer.getCurrentTime());
  138.   }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement