Here is a piece of code in PBasic 2.5
IF p1_sw_top=1 AND p2_sw_top=1 then
p1_y=200
This means that at any given time, if p1 switch and p2 switch are pressed together p1_y=200, but here is my question:
Is there a way that you can program so that the switches will have to be pressed in order- first p1 switch and then p2 switch or vice versa- then only p1_y=200???
yes, you can do that very simply, using 2 for, next loops:
sw1:
if p1_sw_top = 1 then sw2
goto endswich
sw2:
if p2_sw_top = 1 then dostuff:
goto endswich
Dostuff:
p1_y = 200
endswich:
the program will process the first loop, then only if that requirement is met, go to the second loop. if the requirement isnt met at either button, or at the second, not the first, it bypasses the dostuff loop ^.^
'in variable declaration section
seq1_flag VAR bit
'in main loop
'Check 2nd condition first to allow for continuous action, and not just one loop
if p2_sw_top = 1 AND seq1_flag = 1 then run_seq1
'Check first condition
if p1_sw_top = 0 then skip_seq1
'if we got here, condition 1 is true, set flag
seq1_flag = 1
'jump out of sequence loop
goto seq1_done
skip_seq1:
'first condition is not met, clear flag
seq1_flag = 0
'jump out of sequence loop
goto seq1_done
run_seq1:
'both conditions met, set value
p1_y = 200
seq1_done:
'end of sequence loop
No. The code you posted doesn’t actually take the order you pressed the switches into account. The switch variables don’t get updated until you do a SERIN, so you need a way to keep track of stuff between the loops.