Remember that IF...ElseIf instruction blocks exit after executing one section of the code that matches.
Go back to the basics of what you are after, to get it working, then simplify it.
[code:1:bad8da0384]
Pseudo-code:
'Read the state of the switches:
Read Switch 1 save as Switch1status
Read Switch 2 save as Switch2status
Read Switch 3 save as Switch3status
Read Switch 4 save as Switch4status
'Turn Off all of the LEDs, will turn them on only if the correct switches are pressed:
Reset LED1
Reset LED2
Reset LED3
Reset LED4
'Check your current switch status' and do your logic:
If Switch2status = 1 then 'Sw 2 is On, good so far, look at other switches
If Switch4 status = 1 then 'Sw 4 is On, good so far, make sure the other switches are Off
If Switch1status = 0 then 'Sw 1 is Off, good so far, check the last switch
If Switch3status = 0 then 'OK, the correct combination is found, turn ON LED2 and LED 4
Set LED2
Set LED4
Endif
Endif
Endif
Endif
Loop forever
[/code:1:bad8da0384]
At any point along the "decision tree" if the correct switch settings are not found, it exits.
The LEDs are already off in this case.
Only if each switch is set correctly will one reach the inner section of code which turns the LEDs on.
If the Switches are all on the same port, then one can read the port, mask off the other bits, and simplifly the test to one line.
Try this after you get the "basic" method above working.
Do post back on your progress!
JC
↧