Shop OBEX P1 Docs P2 Docs Learn Events
How do I write some code to turn a led ON and OFF with this code — Parallax Forums

How do I write some code to turn a led ON and OFF with this code

sam_sam_samsam_sam_sam Posts: 2,286
edited 2011-02-16 10:55 in Propeller 1
   pub wait_press(pin, ms) | debounce, t

'' waits for (active-high) button press of ms milliseconds

  dira[pin] := 0                                                ' set pin to input mode

  debounce := 0                                                 ' clear debounce timer

  t := cnt                                                      ' sync with system cnt
  repeat until (debounce == ms)                                 ' wait specified db time
    waitcnt(t += clkfreq/1_000)                                 ' hold 1ms
    debounce := ++debounce * ina[pin]                           ' scan input

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-02-16 10:55
     if(debounce)
      ToggleLED(1)
    
    PUB ToggleLED(Led)
      dira[Led] := 1
      outa[Led] := !outa[Led]  
    

    This is a double post!
Sign In or Register to comment.