DreamZ
August 17, 2018, 11:19pm
#1
int switchState = 0;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop() {
switchState = digitalRead(2);
if (switchState = LOW){
digitalWrite(3,HIGH); //green
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
else{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(250); // ms
digitalWrite(4,HIGH);
digitalWrite(5,LOW );
delay(250);
}
}
Can anyone tell me why my circuit doesn’t work? It just blinks the 2 red light.
MAS3
August 18, 2018, 12:13am
#2
Hi.
Please read How to use this forum (click !) , and its links.
I’m wondering if that switch of yours is mounted in the correct orientation.
So try what happens if you:
Either rotate that switch 90 degrees, or make a connection between breadboard pins h21 and h23.
Then see what it does.
DreamZ
August 18, 2018, 12:35am
#3
Nope, nothing happens. It looks like my switch state is never zero.
Wawa
August 18, 2018, 12:50am
#4
if (switchState = LOW) // make switchState low
if (switchState == LOW) // test if switchState is low
Leo..
DreamZ
August 18, 2018, 1:02am
#5
thank you so much.. damn I made a silly mistake in the code.