Hi All, I am completely new to Arduino and am a complete noob.
I am using the Arduino starter kit and on the project 2, Spaceship Interface, the lights and the switch are doing the opposite of what is intended.
At the "low" state (button not pressed), output 4 and 5 blink. When the button is pressed, output 3 lights up and 4 and 5 turn off.
To correct this, I changed switchState to HIGH and it works but I want to know what I did wrong to cause this mix up. Below with the code that makes it work as intended but with the altered switchState line Thanks!
int switchState = 0;
void setup(){
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop(){
switchState = digitalRead(2);
// this is a comment
if(switchState == HIGH) {
// the button is not pressed
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED
}
else { // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to the beginning of the loop