#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define relayPin 10
#define buzzerPin 11
#define setButtonPin 2
#define upButtonPin 3
#define downButtonPin 4
#define startButtonPin 5
LiquidCrystal_I2C lcd(0x27, 16, 2);
int timerSeconds = 0;
bool setupMode = false;
bool timerRunning = false;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(setButtonPin, INPUT_PULLUP);
pinMode(upButtonPin, INPUT_PULLUP);
pinMode(downButtonPin, INPUT_PULLUP);
pinMode(startButtonPin, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.clear();
//Splash Screen
lcd.setCursor(2,0);
lcd.print("IDY CREATIONS");
lcd.setCursor(1,1);
lcd.print("Curing Station");
delay(2000);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Press Setup");
}
void loop() {
checkButtons();
if (setupMode) {
displaySetupMode();
} else if (timerRunning) {
displayTimer();
}
}
void checkButtons() {
if (digitalRead(setButtonPin) == LOW) {
// Set button is pressed, enter setup mode
setupMode = true;
while (digitalRead(setButtonPin) == LOW) {
// Wait for the button to be released
delay(10);
}
}
}
enum SetupState {
DISPLAY_SETUP,
WAIT_FOR_BUTTON_RELEASE,
};
SetupState setupState = DISPLAY_SETUP;
void displaySetupMode() {
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Set Timer");
lcd.setCursor(2,1);
lcd.print("Seconds: " + String(timerSeconds));
unsigned long lastButtonCheckTime = 0;
const unsigned long buttonCheckInterval = 100;
while (setupMode) {
if (millis() - lastButtonCheckTime >= buttonCheckInterval) {
// Update timerSeconds when up or down buttons are pressed
if (digitalRead(upButtonPin) == LOW) {
timerSeconds += 30;
lcd.clear();
//Display setup time with new value after Up button is pressed
lcd.setCursor(2,0);
lcd.print("Set Timer");
lcd.setCursor(2,1);
lcd.print("Seconds: " + String(timerSeconds));
delay(200); // Debounce
setupState = WAIT_FOR_BUTTON_RELEASE;
}
if (digitalRead(downButtonPin) == LOW) {
timerSeconds = max(0, timerSeconds - 30);
lcd.clear();
//Display setup time with new value after down button is pressed
lcd.setCursor(2,0);
lcd.print("Set Timer");
lcd.setCursor(2,1);
lcd.print("Seconds: " + String(timerSeconds));
delay(200); // Debounce
setupState = WAIT_FOR_BUTTON_RELEASE;
}
if (digitalRead(startButtonPin) == LOW) {
// Start button pressed, exit setup mode and start timer
setupMode = false;
timerRunning = true;
digitalWrite(relayPin, HIGH); // Turn on the relay
delay(200); // Debounce
digitalWrite(buzzerPin, HIGH);
delay(100); // Buzzer sound for .1 seconds
digitalWrite(buzzerPin, LOW);
}
lastButtonCheckTime = millis();
}
}
}
void displayTimer() {
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Time Remaining");
lcd.setCursor(6,1);
lcd.print(timerSeconds / 60); // Minutes
lcd.print(":");
if (timerSeconds % 60 < 10) {
lcd.print("0");
}
lcd.print(timerSeconds % 60); // Seconds
// Update the timer every second
delay(1000);
if (--timerSeconds < 0) {
// Timer done, turn off relay, activate buzzer, and reset
digitalWrite(relayPin, LOW);
digitalWrite(buzzerPin, HIGH);
delay(2000); // Buzzer sound for 2 seconds
digitalWrite(buzzerPin, LOW);
timerRunning = false;
timerSeconds = 0;
setupMode = true; // Set up mode after the timer is done
}
}