I'm starting to learn how to use Arduino and I trytried to make this code, which is just a simple if else statement,statement; what I want to make is when the input is LOW, the ledLED 1 is HIGH and ledLEDs 2,3 isare LOW., and when the input is HIGH, the ledLEDs 2,3 isare HIGH and LED 1 is LOW. I wrote this code but when I put the switch in LOW, instead having just like what I intended, all the output isoutputs are HIGH.
I try changing the output and I checked all the wiring to the ledLEDs so my mistake is in the code.
Could you guys tell me what's wrong with the code.
Thank you?
int switchstate = 0;
void setup() {
pinMode (13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(3,INPUT);
}
void loop() {
switchstate = digitalRead(3);
if (switchstate == LOW) {
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
else {
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
}
}