Help with waitpeq
I need a little assistance with waitpeq.
I am trying to monitor several pins. Each pin would be connected to a button. Once a button is pressed (and held), I want the program to wait until the button is released (i.e. wait for the pin to go low).
Take a look at the below code. As it stands, the program never makes it past the waitpeq commands. If I change waitpeq to waitcnt(clkfreq + cnt), I believe the rest of the code works.
I am trying to monitor several pins. Each pin would be connected to a button. Once a button is pressed (and held), I want the program to wait until the button is released (i.e. wait for the pin to go low).
Take a look at the below code. As it stands, the program never makes it past the waitpeq commands. If I change waitpeq to waitcnt(clkfreq + cnt), I believe the rest of the code works.
VAR long stack[noparse][[/noparse]30] byte pin PUB Main | start_pin, cur_pin cognew(PinWatch,@stack[noparse][[/noparse]0]) dira[noparse][[/noparse]8..15] := %11011011 waitcnt(clkfreq*2 + cnt) repeat ' start_pin := pin repeat until cur_pin <> start_pin AND cur_pin <> 0 cur_pin := pin if cur_pin < start_pin outa[noparse][[/noparse]8..9] := %11 waitpeq(%0000, |< cur_pin, 0) !outa[noparse][[/noparse]8..9] if cur_pin > start_pin outa[noparse][[/noparse]14..15] := %11 waitpeq(%0000, |< cur_pin, 0) outa[noparse][[/noparse]14..15] := %00 if cur_pin == start_pin outa[noparse][[/noparse]11..12] := %11 waitpeq(%0000, |< cur_pin, 0) !outa[noparse][[/noparse]11..12] PUB PinWatch repeat if ina[noparse][[/noparse] 3] pin:=3 if ina[noparse][[/noparse] 2] pin:=2 if ina[noparse][[/noparse] 1] pin:=1
Comments
In which waitpeq is it waiting forever? Did you attach LEDs to the output-pins? Then you could tell us.
I suppose you wired the buttons correctly?! Pin 1 on the propeller is port bit 0. As you use ina[noparse][[/noparse]1] to ina[noparse][[/noparse]3] you have to attach the buttons to pin 2 to pin 4.
Buttons are wired correctly. I have the great little sticker that maps out the pins for easy reference on the chip I am using.
The program actually stalls no matter which direction (up or down) I go. Again, if waitcnt is used in place of waitpeq, everything seems fine, except the third 'if' statement.
I realize that if I wanted to use waitpeq to wait until the pin goes high, I could use this:
Is there a way to do this, with a variable, when the pin goes low?
As you predicted, if I press the same button twice, the third if statement does not work. I realize this now that this is due to the line
I'm thinking I can accomplish what I want by using the waitpne command.
LEDs are connected to pins 8-9, 11-12, 14-15 for debugging purposes.
can you please describe in NORMAL words what you are trying to do ?
please NO code just normal words
best regards
Stefan