Hello, I have a (possibly?) unusual problem and was wondering if someone could help please
I am trying to mock up a circuit (as a proof of concept for a larger project). This version has 2 buttons and 2 LEDs.
What I want to happen is that when the Green button is pressed, the Green LED lights and latches on, and the text "Green" is sent to the serial port. (eventually I will use an external serial port, but for the time being I am just monitoring on the Serial Monitor.
When the black button is pressed, I want the green LED to go out and the red LED to latch on, and the text "Black' to be sent.
What is actually happening is that as soon as I press the green button, it send the text over and over and over and over... also, I haven't managed to work out the latching thing but I will work it out
Please note that I have reversed the high and low, think this is due to my circuit but it's not a huge deal. Also, I haven't put the code in for the black button - but I assume it's the same as the green button one?
Thanks
Cheers
David
// Define the pins
const int GreenButton = 7;
const int BlackButton = 8;
const int RedLED = 5;
const int GreenLED = 6;void setup() { //Setup the pin modes
pinMode(GreenButton, INPUT);
pinMode(BlackButton, INPUT);
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
}void loop() {
int stateGreenButton = digitalRead(GreenButton); //read the state of the Green button
if(stateGreenButton == 1){ //if it is pressed
digitalWrite(GreenLED, LOW); //write 1 or HIGH to Green LED Pin ((NOTE: REVERSED))
} else { //if not pressed
digitalWrite(GreenLED, HIGH); //write 0 or LOW to Green LED pin ((NOTE: REVERSED))
}}