Shop OBEX P1 Docs P2 Docs Learn Events
How to use waitpeq — Parallax Forums

How to use waitpeq

Skynet_IncSkynet_Inc Posts: 5
edited 2014-07-24 02:13 in Learn with BlocklyProp
Here is another spin question. Again apologies if it is stupid.

How to you use waitpeq? Im writing a code that counts the number of times a push button is pressed. the circuit i have is a step down switch so the input pin is high when the switch is open and low when the switch is closed. Here is my code:

obj
pst : "parallax serial terminal"


CON
_clkmode=xtal1+pll16x
_xinfreq=5000000


VAR
long counter
long stack[20]


PUB main
dira[3]~ 'set pin 3 to input
pst.Start(115200) 'start serial terminal


pst.str(String("A" ,13)) 'testing where stuff is going wrong
'cognew(checkbutton,@stack) 'start a cog that matches LED pin 20 to input pin 3


counter:=0
pst.str(String("B",13)) 'testing where stuff is going wrong
repeat
pst.Dec(counter)
pst.newline
waitpeq(0,3,0) 'waits untill pin 3 is in low(0)
counter++
waitpeq(1,3,0) 'waits untill pin 3 is in high(1)


'PUB checkbutton
' dira[3]~
' dira[20]~~


' repeat
' outa[20]:=ina[3]

I have tried variations of this such as using
waitpeq(%000000,3,0)
counter++
waitpeq(%100000,3,0)

but I'm still stumped?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2014-07-24 02:06
    waitpxx takes pin masks not numbers. IOW to monitor pin 3 you'd use waitpeq(|< 3, |< 3, 0) to wait for it to become 1 and waitpne(|< 3, |< 3, 0) or waitpeq(0, |< 3, 0) to wait for 0.
  • Skynet_IncSkynet_Inc Posts: 5
    edited 2014-07-24 02:13
    It now works perfectly thank you.
Sign In or Register to comment.