I am in the middle of a project and I need help. New to programming and new to Arduino.
I need to wire 4 light bulbs, all same color. There are three buttons to push in a certain sequence (one button will push for a second time at some point). The led go ON as you push and stay ON if you follow the right sequence. If you push the buttons in a wrong sequence, all lights go OFF immediately after the wrong push(reset). When the right sequence is done, all LEDs stay on and one more output follows.
The pushing needs to react to pushing once and possibly have the same effect if someone keeps on pushing it. It should not matter.
I searched the net, found the wiring (but could use help with that too), but I have problems with the code. I will not attach the code as I am not a programmer and my code sucks:).
Will pay for services, have no idea how much this could cost. Please send me a message with suggestions. Thanks!
I just finished making a telephone for 2 year old grandson with buttons and lights. Here is code to read your 4 buttons. The 'delay (2000)' is ugly programing. Google "Arduino debounce" to find a better way to avoid reading the button too many times. Also it's a bad idea to use 'goto'.
int buttonsSequence[] = {2, 4, 3, 2}; // This array means the user should push button connected to pin 2,;
// then 4 then 3 then 2;
bool butPush;
void setup() {
for (int x = 2; x <= 4; x++) {
pinMode (x, INPUT_PULLUP); //This loops sets the digital input for buttons at pins 2,3 and 4
}
Serial.begin(9600);
delay(1500);
Serial.println ("waiting for buttons to be pushed");
}
void loop() {
for (int a = 0; a <= 3; a++) { // loop through 4 tests
butPush = false;
while (!butPush) {
for (int b = 2; b <= 4; b++) {
if (digitalRead(b) == 0) {
butPush = true;
if (b == buttonsSequence [a]) { // do whatever you want when they pushed the correct button
Serial.print ("pushed the correct button - at pin number...");
Serial.println (b);
delay (2000);
}
else { // do whatever you want when they pushed the wrong button
Serial.print ("pushed the WRONG BUTTON, at pin number...");
Serial.println (b);
delay (2000);
goto wrongbut;
}
}
}
}
}
wrongbut:
Serial.println ("starting over, waiting for buttons to be pushed");
}