i am trying to create a program that will display on an LCD screen. Here are the parameters of the program.
- Welcome Screen.
- Select one of three Puzzles.
- If press a start button within 10 secs.
-----if start not press, return to welcome screen.
-----if start pressed, go to a countdown. - each puzzle has a different time.
this is what I have so far as the code but what i need help with is with the start button.
I have the Welcome Screen, Puzzle is selected, Timer for start button to be pressed, if timer = 0 - goes back to welcome screen. When i press the start button, nothing happens. Please let me know what I can do to get the program working. Thanks.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,10,9,8,7);
const int numRows=4;
const int numCols=16;
unsigned long time;
#define ON 0
#define READY 1
#define START 2
#define COUNTDOWN 3
#define STOPPED 4
int count;
int pState = 0;
int startPin = 3; //START pushbutton
int stopPin = 2; //STOP pushbutton
int ponePin = 4; //Puzzle 1 pushbutton
int ptwoPin = 5; //Puzzle 2 pushbutton
int pthreePin = 6; //Puzzle 3 pushbutton
void setup()
{
Serial.begin(9600);
lcd.begin(numRows, numCols);
}
void welcome()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" WELCOME “);
lcd.setCursor(0,1);
lcd.print(” PLEASE SELECT “);
lcd.setCursor(0,2);
lcd.print(” A PUZZLE ");
delay(500);
pState = READY;
}
void puzzleselected()
{
int P1 = digitalRead(ponePin);
int P2 = digitalRead(ptwoPin);
int P3 = digitalRead(pthreePin);
if(P1 == HIGH)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Puzzle 1 Selected “);
lcd.setCursor(0, 1);
lcd.print(” 1:00 MIN “);
lcd.setCursor(0, 2);
lcd.print(” Press START “);
}
else if(P2 == HIGH)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” Puzzle 2 Selected “);
lcd.setCursor(0, 1);
lcd.print(” 2:00 MIN “);
lcd.setCursor(0, 2);
lcd.print(” Press START “);
}
else if(P3 == HIGH)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” Puzzle 3 Selected “);
lcd.setCursor(0, 1);
lcd.print(” 3:00 MIN “);
lcd.setCursor(0, 2);
lcd.print(” Press START ");
}
pState = START;
}
void countdown()
{
int P1 = digitalRead(ponePin);
int P2 = digitalRead(ptwoPin);
int P3 = digitalRead(pthreePin);
if(P1 == HIGH)
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" Puzzle 1 Started “);
lcd.setCursor(0,2);
lcd.print(” countdown “);
delay(1000);
}
else if(P2 == HIGH)
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print(” Puzzle 2 Started “);
lcd.setCursor(0,2);
lcd.print(” countdown “);
delay(1000);
}
else if(P3 == HIGH)
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print(” Puzzle 3 Started “);
lcd.setCursor(0,2);
lcd.print(” 00:00 ");
delay(1000);
}
}
void loop()
{
int P1 = digitalRead(ponePin);
int P2 = digitalRead(ptwoPin);
int P3 = digitalRead(pthreePin);
int start = digitalRead(startPin);
int stop = digitalRead(stopPin);
switch (pState)
{
/*
Welcome Screen
/
case ON:
if(P1 == LOW && P2 == LOW && P3 == LOW)
{
welcome();
}
else
{
pState = READY;
}
break;
/
READY - Puzzle Selected
/
case READY:
if(P1 == HIGH)
{
digitalWrite(ponePin, HIGH);
puzzleselected();
}
else if(P2 == HIGH)
{
digitalWrite(ptwoPin, HIGH);
puzzleselected();
}
else if(P3 == HIGH)
{
digitalWrite(pthreePin, HIGH);
puzzleselected();
}
break;
/
Wait for START to be pressed
*/
case START:
for(count = 10; count >= 0; count–)
{
digitalRead(startPin);
lcd.setCursor(1, 3);
lcd.print(“RESET in”);
lcd.setCursor(14, 3);
lcd.print(“00:”);
time = millis();
if(count <= 9)
{
lcd.print(‘0’);
}
lcd.print(count);
delay(1000);
if(count == 0);
pState = ON;
if(start == HIGH);
pState = COUNTDOWN;
}
break;
case COUNTDOWN:
if(P1 == HIGH)
{
countdown();
}
else if(P2 == HIGH)
{
digitalWrite(ptwoPin, HIGH);
countdown();
}
else if(P3 == HIGH)
{
digitalWrite(pthreePin, HIGH);
countdown();
}
break;
case STOPPED:
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" CONGRATULATIONS “);
lcd.setCursor(0,2);
lcd.print(” PUZZLE SOLVED ");
delay(1000);
//insert delay time
break;
}//Closes "Switch
}//Closes “loop”
Switch_3.ino (3.98 KB)