Shop OBEX P1 Docs P2 Docs Learn Events
Pushbutton - normally open — Parallax Forums

Pushbutton - normally open

Tony11Tony11 Posts: 41
edited 2010-04-28 02:30 in Propeller 1
What I need help with, is. I want to know how to program pushbutton switch and led. When you push and let go of the switch, led will turn on and stay on, till you push the switch, for the second time. Then led will go off. So like A Latch.




I do know how to program ButtonToLed.








'' File: ButtonToLed
'' Led mirrors pushbutton state.
PUB ButtonLed    ' Pushbutton/Led Method
dira[noparse][[/noparse]6] := 1    ' P6 → output
dira[noparse][[/noparse]22] := 0    ' P22 → input (this command is redundant)
repeat    ' Endless loop
outa[noparse][[/noparse]6] := ina[noparse][[/noparse]22]    ' Copy P22 input to P6 output











Thank you

Comments

  • KyeKye Posts: 2,200
    edited 2010-04-28 01:08
    PUB buttonLatch(inPin, outPin)
     
      dira[noparse][[/noparse]outPin] := 1
      dira[noparse][[/noparse]inPin] := 0
     
      outa[noparse][[/noparse]outPin] := ina[noparse][[/noparse]inPin]
      repeat
     
        repeat while(ina[noparse][[/noparse]inPin] == 0)
        waitcnt((clkfreq / 100) + cnt) ' Debounce timeout.
        repeat while(ina[noparse][[/noparse]inPin] == 1)
        waitcnt((clkfreq / 100) + cnt) ' Debounce timeout.
     
        outa[noparse][[/noparse]outPin] ^= 1 ' Flip out pin state.
    


    This should work. I reconmend looking for the button debouncer driver I posted in the obex and using it to look for when the button has been pressed. Each time the button is pressed you simply flip the out state.







    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Tony11Tony11 Posts: 41
    edited 2010-04-28 02:23
    What is the obex? I reconmend looking for the button debouncer driver I post. Where can I
    find this post?
  • computer guycomputer guy Posts: 1,113
    edited 2010-04-28 02:30
    obex.parallax.com/objects/585/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "powered by Propeller" domed stickers $1.50 - Find them here
    Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net

    The Sarah Myatt Fund - Help Sarah and Her Family Fight Quadriplegia HERE
Sign In or Register to comment.