I do have a code I will show it down below, I tested everything and I upload it to arduino coding but it’s says so many errors. I’m not sure if I did it right I have never used an lcd before.
#include <LiquidCrystal.h>
const uint8_t button = 8;
const uint8_t LedG = 6, LedY = 13, LedR = 7:
const uint8_t Buzzer = 9;
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
const unsigned long TURN_MS = 10000;
const unsigned long WARN_Y_MS = 4000;
const unsigned long WARN_R_MS = 2000;
Volatile bool buttonPressed = false;
Unsigned long lastbuttonTime = 0;
enum state {IDLE, RUNNING, TIMEOUT } state = IDLE;
unsigned long deadline = 0;
Void onButton() {
Unsigned long now = millis();
If (now - lastbuttonTime > 80) {
buttonpressed = true;
lastbuttonTime = now;
}
}
Void beep(int fre, int ms, int pause=60){
tone(Buzzer, freq, ms);
delay(ms + pause);
Void startTurn(){
deadline = millis() + TURN_MS;
state = RUNNING;
for (int i=0; i<2; i++) { beep(1000, 80, 70); }
}
void lightsFor(unisgned long remain){
digitalWrite(LedG, remain > WARN_Y_MS);
digitalWrite(LedY, (remain <= WARN_Y_MS && remain > WARN_R_MS));
digitalWrite(LedR, remain <= WARN_R_MS);
}
void lcdShow(unisgned long remainMs){
lcd.setCursor(0,0): lcd. print(“ Timer Run “);
lcd.setCursor(0,1);
char line2[17];
snprintf(line2, 17, “Time: %3lus “, remainMs/1000);
lcd.print(line2);
}
void setup(){
pinMode (button, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button), onButton, FALLING);
pinMode (LedG, OUTPUT);
pinMode (LedY, OUTPUT);
pinMode (LedR, OUTPUT);
pinMode (Buzzer, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(“Press to start “);
lcd.setCursor(0,1);
lcd.print(“ Brain Countdown Timer “);
}
void loop(){
If (buttonPressed){
buttonPressed = false;
startTurn();
}
if (state == RUNNING) {
long remain = (long)deadline - (long)millis();
if (remain <= 0) {
state = TIMEOUT;
int tones[] = {1200, 1000, 800, 600, 400};
for (uint8_t i = 0; i < 5; i++) { beep(tones[i], 120, 30); }
for (int i=0; i<3 && state==TIMEOUT; i++) {
digitalWrite(LedR, HIGH);
delay(150);
digitalWrite(LedR, LOW);
delay(150);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print (“ TIME IS UP “);
lcd.setCursor(0,1);
lcd.print (“Thanks For Playing”);
} else {
lightsFor(remain);
lcdShow(remain);
}
}
}