Shop OBEX P1 Docs P2 Docs Learn Events
Help with waitpeq — Parallax Forums

Help with waitpeq

AJMAJM Posts: 171
edited 2009-11-10 17:37 in Propeller 1
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.

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

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-11-10 07:38
    You want to detect if the button pushed is bigger or lower than the one before? That's what I think the if statements will do. But if you push the same button again it won't work. You only leave the repeat loop when cur_pin <> start_pin. So, your if-statement cur_pin==start_pin will never be true.

    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.
  • AJMAJM Posts: 171
    edited 2009-11-10 13:29
    You are correct. I do want to sense a series of buttons and execute methods (not implemented yet) based on which direction the buttons are pressed.

    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:
    waitpeq(|< cur_pin, |< cur_pin, 0)
    
    



    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

    repeat until cur_pin <> start_pin AND cur_pin <> 0
    
    



    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.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-11-10 17:37
    Hello AJM,

    can you please describe in NORMAL words what you are trying to do ?
    please NO code just normal words

    best regards

    Stefan
Sign In or Register to comment.