i need a code that will code my protoype oven in arduino sketch software it has three buttons, 1 buzzer and one led and an lcd
the code should do the following
- the lcd should not display anything until one of hte three buttons is pressed
- when one of the three buttons is pressed, the lcd should turn on saying "set timer"
- then the user will set it in minutes using pin up to increase in minutes and pin down to decrease in minutes, then the select is to start the timer
- when the timer finishes, the buzzer and light should go on and another countdown timer(one minute) to automatically shut off the oven((turn off the lcd) should start
- the buzzer and light should not turn off until a button is pressed during the auotmatic oven shut off or until the one miinute counter finishes
- if a button is pressed it should go back to the set timer screen but if the one minute counter finishes the lcd should clear and go off and the buzzer should go off too and the light
- miind you when i mean the buzzer and light should come on i want the light to be flashiing and the buzzer too
the code doesnt do what its supposed to do and i dont know whats wrong
here is the code
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
const int pin_up = A0; // the pin that the button is connected to
const int pin_down = A1;//pin that button 2 is connected to
const int pin_select = A2;//pin that button 3 is connected to
const int buzzer = 8;//pin that buzzer is connected to
const int light = 13;//pin that light is connected to
int state_up = 0; // variable for storing the button state
int state_down = 0;
int state_select = 0;
int OvenState = 0;
int minutes = 0; // initial value of the timer
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows
pinMode(pin_up, INPUT); // set the button pin as input
pinMode(pin_down, INPUT);
pinMode(pin_select, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(light, OUTPUT);
}
void loop() {
switch (OvenState) //switch case to determine oven state
{
case 0:
if (digitalRead(pin_up) == HIGH || digitalRead(pin_down) == HIGH || digitalRead(pin_select) == HIGH) {
lcd.clear();
OvenState = 1;
}
break;
case 1:
if (digitalRead(pin_up) == HIGH) {
delay(200);
minutes++;
}
if (digitalRead(pin_down) == HIGH) {
delay(200);
minutes--;
if (minutes < 0) {
minutes = 0;
}
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set timer:");
lcd.setCursor(0, 1);
lcd.print(minutes);
lcd.display();
if (digitalRead(pin_select) == HIGH) {
minutes *= 60;
OvenState = 2;
delay(200);
}
break;
case 2:
while (minutes > 0 && OvenState == 2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time remaining: ");
lcd.setCursor(0, 1);
lcd.print(minutes / 60);
lcd.print(":");
if (minutes % 60 < 10) {
lcd.print("0");
}
lcd.print(minutes % 60);
delay(1000);
minutes--;
if (minutes == 0) {
lcd.clear();
lcd.print("Times Up!");
delay(2000);
OvenState = 3;
break;
}
if (digitalRead(pin_select) == HIGH)
{
lcd.clear();
minutes = 0;
OvenState = 1;
delay(200);
break;
}
}
case 3:
if (OvenState == 3) {
int seconds = 60;
lcd.clear();
lcd.print("Oven will shut off in: ");
lcd.setCursor(0, 1);
lcd.print("1:00");
// Start buzzer and flashing light
pinMode(buzzer, OUTPUT);
pinMode(light, OUTPUT);
digitalWrite(buzzer, LOW);
digitalWrite(light, LOW);
bool isBuzzerOn = false;
bool isLightOn = false;
unsigned long prevTime = millis();
bool isButtonPressed = false;
while (seconds > 0 && !isButtonPressed) {
unsigned long currentTime = millis();
if (currentTime - prevTime >= 500) {
prevTime = currentTime;
if (isBuzzerOn) {
digitalWrite(buzzer, LOW);
isBuzzerOn = false;
} else {
digitalWrite(buzzer, HIGH);
isBuzzerOn = true;
}
if (isLightOn)
{
digitalWrite(light, LOW);
isLightOn = false;
} else {
digitalWrite(light, HIGH);
isLightOn = true;
}
}
lcd.setCursor(0, 1);
lcd.print("0:");
if (seconds < 10)
{
lcd.print("0");
}
lcd.print(seconds);
if (digitalRead(pin_select) == LOW)
{
isButtonPressed = true;
}
delay(1000);
seconds--;
}
// Turn off buzzer and light
digitalWrite(buzzer, LOW);
digitalWrite(light, LOW);
pinMode(buzzer, INPUT);
pinMode(light, INPUT);
// Clear LCD and return to Case 1 if a button was pressed
if (isButtonPressed) {
lcd.clear();
OvenState = 1;
}
}
}
}