Hello,
I just write my first code ever for a small project I have, its sound basic but im lost right now and will need some help.
My goal is simple, its kind of a question True or False game, I have 6 question , 1 true and 1 false buttons. The user must press and hold one "question button" then press true or false, if the answer is right, 1 of the 6 led ( one by question) light up and stay light.
So far my code do exactly that... I know its crude and I should use array but its already a miracle that its working first time.
The problem is I dont know how to make the game reset when its done and also add a inactivity timer reset
When its done (6 led light up)the game should reset but lets some time to the user to see all the led light up say 5 second then start again.
Also when its resetting whatever inactivity or when its done after the 5 sec, I wonder if its hard to make it blink for like 3 sec ( not critical will just look cool).
Its possible that I add thing into my code that I dont need... I try to copy a couple of basic tutorial and some exemple I saw online , anyway here my code:
/*
Test on MEGA 2560, must be use on UNO later
*/
const int buttonF = 30; // button False , to replace by 14 (analog 0) with the Uno
const int buttonT = 31; // button True , to replace with 15(analog 1) with the Uno
const int button1 = 2; // button question 1
const int button2 = 3; // button question 2
const int button3 = 4; // button question 3
const int button4 = 5; // button question 4
const int button5 = 6; // button question 5
const int button6 = 7; // button question 6
const int led1 = 13;
const int led2 = 12;
const int led3 = 11;
const int led4 = 10;
const int led5 = 9;
const int led6 = 8;
int buttonStateT = 0;
int buttonStateF = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(buttonF, INPUT);
pinMode(buttonT, INPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
}
void loop() {
// check if the pushbutton is pressed.
buttonStateT = digitalRead(buttonT);
buttonStateF = digitalRead(buttonF);
buttonState1 = digitalRead(button1);
buttonState2 = digitalRead(button2);
buttonState3 = digitalRead(button3);
buttonState4 = digitalRead(button4);
buttonState5 = digitalRead(button5);
buttonState6 = digitalRead(button6);
if (buttonState1 == HIGH && buttonStateT == HIGH) { // If button1 and buttonT are pressed
digitalWrite(led1, HIGH); // Light led1
}
if (buttonState2 == HIGH && buttonStateT == HIGH) { // If button2 and buttonT are pressed
digitalWrite(led2, HIGH); // Light led2
}
if (buttonState3 == HIGH && buttonStateT == HIGH) { // If button3 and buttonT are pressed
digitalWrite(led3, HIGH); // Light led3
}
if (buttonState4 == HIGH && buttonStateF == HIGH) { // If button4 and buttonF are pressed
digitalWrite(led4, HIGH); // Light led4
}
if (buttonState5 == HIGH && buttonStateF == HIGH) { // If button5 and buttonF are pressed
digitalWrite(led5, HIGH); // Light led5
}
if (buttonState6 == HIGH && buttonStateF == HIGH) { // If button6 and buttonF are pressed
digitalWrite(led6, HIGH); // Light led6
}
}
I will appreciate some some help or point me in the right direction,
Thanks in advance