Hi, I've never used this forum before so I'm sorry if I'm not doing this right but I'm trying to simulate a bomb for an digital escape room for one of my classes. The end goal is to have a timer count down and use the buttons to "disarm the bomb" and stop the timer and if the player runs out of time tell them. I want to use a specific sequence of button presses to do so. So far I have been able to get everything to work except the order of the button presses. For example, I want the player to press the blue button 6 times then the red button 7 times followed by the green button 5 times, which would display the ending message. If the player guesses incorrectly I want the timer to keep running and them to be able to guess again.
In my many attempts to get my code to work I added the step that they have to press all 3 buttons at the same time when they are done pressing the sequence to signify that they are done. As of right now my code does everything its supposed to except for the fact that if I press the buttons out of order it still displays the congratulatory message. If anyone can help me change my code so that only the right sequence of button presses displays the congratulatory message I would greatly appreciate it.
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int bluePin = 7;
int redPin = 6;
int greenPin = 5;
int contrastPin = 3;
long minute = 29;
long second = 59;
int t = 0;
int x = 0;
int y = 0;
int z = 0;
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("MM:SS");
//set the button pins as inputs
pinMode(redPin, INPUT_PULLUP);
pinMode(greenPin, INPUT_PULLUP);
pinMode(bluePin, INPUT_PULLUP);
analogWrite(contrastPin, 50);
}
void loop() {
if (t == 0){
delay(1000);
second = second - 1;
if (second < 00){
minute = minute - 1;
second = 59;
}
lcd.setCursor(0,1);
lcd.print(minute);
lcd.print(":");
lcd.print(second);
if (second < 10 && minute >= 10){
lcd.setCursor(0,1);
lcd.print(minute);
lcd.print(":0");
lcd.print(second);
}
if (minute < 10 && second >= 10){
lcd.setCursor(0,1);
lcd.print("0");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
}
if (minute < 10 && second < 10){
lcd.setCursor(0,1);
lcd.print("0");
lcd.print(minute);
lcd.print(":0");
lcd.print(second);
}
if (minute < 00){
t = 1;
lcd.setCursor(5,0);
lcd.print("You're");
lcd.setCursor(2,1);
lcd.print("out of time!");
}
combo();
}
}
void combo() {
if (minute > 00 || second > 00){
if (digitalRead(bluePin) == LOW){
x++;
lcd.setCursor(7,0);
lcd.print("b=");
lcd.print(x);
}
if (digitalRead(redPin) == LOW){
y++;
lcd.setCursor(12,0);
lcd.print("r=");
lcd.print(y);
}
if (digitalRead(greenPin) == LOW){
z++;
lcd.setCursor(7,1);
lcd.print("g=");
lcd.print(z);
}
if (digitalRead(bluePin) == LOW && digitalRead(redPin) == LOW && digitalRead(greenPin) == LOW){
if (x != 7 || y != 8 || z != 6){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("That's not right");
lcd.setCursor(3,1);
lcd.print("try again.");
x = 0;
y = 0;
z = 0;
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MM:SS");
} else {
lcd.clear();
lcd.setCursor(1,0);
lcd.print("President Auon");
lcd.setCursor(0,1);
lcd.print("has been saved!!");
t = 1;
}
}
}
}
Also I'm not sure if its my code or if my buttons are just bad, but one press of the button doesn't always register on the display so I usually have to spam it until the number is correct or just press and hold so if someone could help me get the display to register one button press as just that it would be great.
I also don't know which red board and bread board I have but I've attached a picture and the wiring for my set up is as follows (sorry again if this is in the wrong format):
LCD
A15 - A30
Wires from
E15 - (-)
E16 - (+)
E17 - pin3
E18 - pin13
E19 - (-)
E20 - pin12
E25 - pin11
E26 - pin10
E27 - pin9
E28 - pin8
E29 - (+)
E30 - (-)
Blue Button
E1 - H1
E3 - H3
Wires from
I1 - pin7
I3 - (-)
Red Button
E6 - H6
E8 - H8
Wires from
I6 - pin6
I8 - (-)
Green Button
E11 - H11
E13 - H13
Wires from
I11 - pin5
I13 - (-)
Wires from
1(+) - 5V
1(-) - GND
Scanned Documents.pdf (893 KB)