I've been having some trouble making a simple rs latch with my arduino uno R3, whenever I turn on or reset the arduino, it just turns the led on and if I press either of the buttons, nothing happens. I hope someone can help point me in the right direction as everything I have tried hasn't done anything.
const int ledPin = 13;
const int button1 = 8;
const int button2 = 3;
void setup() {
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(button1) == HIGH) {
digitalWrite(ledPin, HIGH);
}
if (digitalRead(button2) == HIGH) {
digitalWrite(ledPin, HIGH);
}
}
The current wiring cannot provide an intentional LOW to the switch inputs. This is because the inputs are either floating (an undesirable state) when the switch is open or connected to 3.3v when the switch is closed. Choose one of the configurations from the schematic below.
Using RS latch code for 2 buttons is quite simple and no debouncing is required. The only condition that might need handling is if the user presses both buttons at the same time. Check here for some examples.