|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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??? |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||||
|
|||||
|
Here's a bit of code which will do what you want:
Code:
'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 |
|
#5
|
||||
|
||||
|
isnt that overkill?
~Pyro |
|
#6
|
||||||
|
||||||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Limit switches | Team168 | Programming | 8 | 10-02-2003 16:22 |
| Custom Pneumatics order form | Andrew Schuetze | Kit & Additional Hardware | 1 | 10-01-2003 20:34 |
| Team selector switches on ISAAC | Lloyd Burns | Robotics Education and Curriculum | 0 | 17-12-2002 08:32 |
| More than 2 aux switches in 1 port | f22flyboy | Programming | 2 | 01-11-2002 14:44 |
| Need help with custom switches | archiver | 2001 | 3 | 24-06-2002 00:35 |