Hello,
I have a school project to make anything using Arduino Uno board. We will make a quiz machine with maybe 4 buttons and 4 LEDs.
My problem is that I cant find the code to make the first pressed button lights an LED, and the other buttons will have no effect until the reset button pressed.
Let me explain more:
Okay so lets say we have a GREEN button and GREEN LED and a RED button and RED LED.
so I want when the GREEN button is pressed the GREEN LED will light up and if the RED button pressed nothing happens.
Till now I have successfully got a code to light the LED wen the buttons are pressed. Both can light at the same time.
Here is my code
#define LEDPIN1 10
#define LEDPIN2 11
#define INPIN1 6
#define INPIN2 7
int state1 = HIGH;
int state2 = HIGH;
void setup() {
Serial.begin(9600);
pinMode(LEDPIN1, OUTPUT);
pinMode(LEDPIN2, OUTPUT);
pinMode(INPIN1, INPUT);
digitalWrite(INPIN1, HIGH); // enable pullup resitor
pinMode(INPIN2, INPUT);
digitalWrite(INPIN2, HIGH); // enable pullup resitor
}
void loop() {
delay(10); // debounces switches
int val1 = digitalRead(INPIN1);
int val2 = digitalRead(INPIN2);
if(state1 != val1 || state2 != val2) {
state1 = val1;
state2 = val2;
digitalWrite(LEDPIN1, val1); // turns the LED on or off
digitalWrite(LEDPIN2, val2); // turns the LED on or off
Serial.print(val1, DEC);
Serial.println(val2, DEC);
}
}
And here is a video of my Arduino