Using WaitPEQ for more than one pin?
garyg
Posts: 420
in Propeller 1
Hi
I'm currently using WaitPEQ in the following manner:
Waitpeq (|<BUTN1, |<BUTN1, 0) 'Pause program execution until button BUTN1 is pressed and held.
This works to monitor BUTN1.
....
If possible, I would like to monitor two different buttons so that the following word description works correctly.
Waitpeq until either BUTN1 or BUTN2 are pressed.
.....
I've tried many different ways to write this, but none of them will compile without error message.
I'm certain that either this is not possible using Waitpeq OR
There is something very fundamental that I do not understand.
I'm using Propeller Tool and Spin.
Any words of wisdom concerning this would be greatly appreciated.
Thanks
GaryG
I'm currently using WaitPEQ in the following manner:
Waitpeq (|<BUTN1, |<BUTN1, 0) 'Pause program execution until button BUTN1 is pressed and held.
This works to monitor BUTN1.
....
If possible, I would like to monitor two different buttons so that the following word description works correctly.
Waitpeq until either BUTN1 or BUTN2 are pressed.
.....
I've tried many different ways to write this, but none of them will compile without error message.
I'm certain that either this is not possible using Waitpeq OR
There is something very fundamental that I do not understand.
I'm using Propeller Tool and Spin.
Any words of wisdom concerning this would be greatly appreciated.
Thanks
GaryG
Comments
(EDIT: This line is wrong, see below.)
This waits until ina & ((|<BUTN1) | (|<BUTN2)) <> 0, or until any of those buttons are pushed.
You can OR as many values together as you like. For example, you could use waitpne(%11111111, 0, 0) waitpne(0, %11111111, 0) to wait for any of pins 0-7 to go high.
EDIT:
As Jason Dorie pointed out, that should be:
I think your state and mask values are backwards:
waitpne( state , mask , port ) 'port is always 0 on Prop1
I believe I would not have come up with those solutions on my own.
I tried Electrodude's solution 1st and it compiled without error.
I'm not sure as yet if it will run correctly yet.
Jason
If I'm understanding correctly, then maybe this also would work?
mask := (|<BUTN1) | (|<BUTN2) | (|<BUTN3) 'OR the 3 button masks together into a single value
waitpne( 0 , mask , 0 ) 'wait for either pin to be set
Thanks again for all your help
Garyg
Perhaps slightly less cryptic:
I know the |< operator exists, but I find the above a little easier to read. If your BUTNx values are constants, you could speed up your code a little by doing this:
constant( x ) tells the Propeller tool to evaluate the function at compile time instead of at run time. Not a huge deal, but it'll save some instructions and some time, IF and only if those BUTN values are constant too.
Thanks. Something in the back of my mind was telling me I should probably consult the Propeller Manual before giving help about an instruction I rarely use...
-Phil