Shop OBEX P1 Docs P2 Docs Learn Events
pushbutton as a slector switch — Parallax Forums

pushbutton as a slector switch

samsn4samsn4 Posts: 49
edited 2007-12-11 15:26 in Propeller 1
in a round about way, would this work?

pb - pushbutton input

pb := 0

case pb
1:
if pb == 0
pb := 1
elseif pb == 1
pb := 2
elseif pb == 2
pb := 0

i'm using a keypad and want to cycle through three different modes with one button

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Daniel Mueth
WSIU-TV Master Control

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Just plug it in and let's see what happens"

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-11 15:14
    How about (with the 1st part the initialization and the 2nd part executed periodically):
    oldValue := 0
    pb := 0
    ...
    newValue := ina[noparse][[/noparse]button]
    if oldValue == 0 and newValue == 1
       pb := (pb + 1) // 3
    oldValue := newValue
    
    

    Post Edited (Mike Green) : 12/11/2007 3:22:52 PM GMT
  • bambinobambino Posts: 789
    edited 2007-12-11 15:25
    In theory yes, but you are mixing a·case structure and if structure! use one or the other.
    if ina[noparse][[/noparse]button] == 1   case pb
          0: pb := 1
          1: pb := 2
          2: pb := 0
    '----------------------------
    

    if ina[noparse][[/noparse]button] == 1
      if pb == 0
       pb := 1
      elseif pb == 1
       pb := 2
      else
       pb := 0
    

    Don't forget to debounce your button some way, either by using a wait count or by waiting for the button to go active and resting before changing your value.
  • bambinobambino Posts: 789
    edited 2007-12-11 15:26
    Dang Mike, we must have been typing at the same instant!
    Sorry, I didn't think any one had answered.
Sign In or Register to comment.