Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
- #include "Countimer.h"
- Countimer timer;
- #include <Button.h>
- #include <EEPROM.h>
- Button startStopBtn(16);
- Button minutesBtn(17);
- Button secondsBtn(18);
- const int backlight = 9;
- const int bell = 15;
- int startHours = 0;
- int startMinutes = 0;
- int startSeconds = 0;
- bool settingsMode = false;
- int bellMillis = 0;
- long bellStartMillis;
- void setup() {
- startStopBtn.begin();
- minutesBtn.begin();
- secondsBtn.begin();
- pinMode(backlight, OUTPUT);
- pinMode(bell, OUTPUT);
- lcd.begin(16, 2);
- digitalWrite(backlight, HIGH);
- lcd.setCursor(0, 0);
- lcd.print(F("World's Loudest"));
- lcd.setCursor(1, 1);
- lcd.print(F("Kitchen Timer"));
- delay(3000);
- bellMillis = (EEPROM.read(0) * 10);
- }
- void onComplete() {
- //activate bell
- //reset or stop timer
- digitalWrite(bell, HIGH);
- delay(bellMillis);
- digitalWrite(bell, LOW);
- }
- void loop() {
- timer.run();
- if (timer.isCounterCompleted() == false && !timer.isStopped() == false) {//timer.isCounterRunning()
- if (settingsMode) {
- if(minutesBtn.pressed()) {
- bellMillis = bellMillis + 100;
- }
- if(secondsBtn.pressed()) {
- bellMillis = bellMillis + 10;
- }
- if(minutesBtn.pressed() && secondsBtn.pressed()) {
- bellMillis = 10;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("Bell Time"));
- lcd.setCursor(0, 1);
- lcd.print(bellMillis);
- if(startStopBtn.pressed()) {
- //save bellMillis to EEPROM
- EEPROM.update(0, (bellMillis / 10));
- settingsMode = false;
- }
- } else {
- if (minutesBtn.pressed()) {
- startMinutes++;
- }
- if (secondsBtn.pressed()) {
- startSeconds++;
- }
- if (startMinutes > 60) {
- startMinutes = 0;
- }
- if (startSeconds >= 60) {
- startSeconds = 0;
- }
- if (minutesBtn.pressed() && secondsBtn.pressed()) {
- startHours = 0;
- startMinutes = 0;
- startSeconds = 0;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("TIMER"));
- lcd.setCursor(0, 1);
- lcd.print(startHours);
- lcd.print(":");
- lcd.print(startMinutes);
- lcd.print(":");
- lcd.print(startSeconds);
- //if startStopBtn is held down, settingsMode = TRUE
- if (startStopBtn.pressed()) {
- timer.setCounter(startHours, startMinutes, startSeconds, timer.COUNT_DOWN, onComplete);
- timer.start();
- }
- }
- }
- if (!timer.isStopped()) {//timer.isCounterRunning()
- if (startStopBtn.pressed()){
- timer.pause();
- }
- if (minutesBtn.pressed() && secondsBtn.pressed()) {
- startHours = 0;
- startMinutes = 0;
- startSeconds = 0;
- timer.stop();
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(F("Timing"));
- lcd.setCursor(0, 1);
- lcd.print(timer.getCurrentTime());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement