![]() |
switches in order
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 declare a latch or memory bit that is set when the first button is pushed and cleared when the second button is pressed.
Tim Tedrow |
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 ^.^ ~Pyro |
Here's a bit of code which will do what you want:
Code:
'in variable declaration section |
isnt that overkill?
~Pyro |
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.
--Rob |
| All times are GMT -5. The time now is 04:27. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi