Hello, Im currently making a capstone project that requieres an lcd to act as a timer. Followed with lcd I’m using a buzzer, three LEDS and a reset button wired automatically to the arduino in the reset pin. And GND wired with pin 8 acting as sensor, the GND wired with be connected to a piece of metal and pin 8 connected to a tweezer so when the tweezers touch the metal the buzzer will buzz.
Problem
Everything works except the primary display message that is start and when button is touched it starts the timer. Also I need to make that when button is touched after a round it will reset to the “start” message. I’m a beginner and I’m not sure how to fix this error. I would provide my code down below.
If anyone can help I would really appreciate it
#include <LiquidCrystal.h>
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int touchSensor;
int buzzer = 9;
int counter;
int green = 6;
int red = 7;
int yellow = 13;
void setup() {
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
pinMode(8, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.clear();
lcd.home();
lcd.print("Start");
counter=0;
}
void loop() {
touchSensor=digitalRead(8);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(counter);
delay (1000);
counter=counter+1;
if(touchSensor == 0){
do {
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
digitalWrite(yellow, LOW);
tone(buzzer, 1000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Game Over!");
delay(5000);
} while (touchSensor == 0);
}
else if(counter == 20){
do {
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
digitalWrite(yellow, LOW);
tone(buzzer,1000);
delay(100);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Game Over!");
delay (5000);
} while (counter=20);
}
else if (counter == 10){
digitalWrite(yellow, HIGH);
digitalWrite(green,LOW);
digitalWrite(red, LOW);
delay(1000);
digitalWrite(yellow, LOW);
digitalWrite(green,LOW);
digitalWrite(red, LOW);
}
else{
digitalWrite(green,HIGH);
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
noTone(buzzer);
}
}