I am fairly new to this and trying to write a small program
this is a small section of it :-
1 if (latch3 == 0) { //stops this repeating for the time loop below
2 if (switchState3 == LOW) { //if switch three is pressed
3 // turn b1yel1 b1yel2 b2yel1 and b3red red on:
4 latch3 = (1);
5 digitalWrite(b1yel1, HIGH); // I have put this line in to prove b1yel1 is high
6 if (b1yel1 == HIGH)
7 digitalWrite(b1yel2, HIGH); //if b1yel1 is on put b1yel2 on
8
9 digitalWrite(b2red, LOW); //turn signal 2 red off
10 digitalWrite(b2yel1, HIGH); //turn signal 2 yel on
11 digitalWrite(b3red, HIGH); //turn signal 3 to red
12 digitalWrite(b3grn, LOW);
13 } //put a time loop in here to stop it repeating then turn latch low (not made yet)
14 }
15 if (switchState3 == HIGH)
16 latch3 = (0);
I must be missing something. I have included the line numbers for this forum. For some reason line 7 doesn't execute?
If I rem line six out it does ( // ), but I only want it to turn b1yel2 on if b1yel1 is on?
Can you see what I am doing wrong?
Thanks,
Bob.
There is a difference between pin numbers and pin values You are comparing a pin number with HIGH, completely illogical,
just remove the 'if' dang nabbit, the pin is high cos you set it high, there is no need to assume it has changed unless you typed the code below inside an interrupt.
matelot:
Why doesn't it work if I just change line 6 to
if (b1yel1 == 1)
?
Because that if statement is checking the value of b1yel1, which is a pin number.
What you're trying to do is to check the state of that pin, not it's value.