Button command Help!
Hello I am very, very new to the Propeller and apologize for such a basic question however i could sure use some direction, I have used pbasic for a number of years but just cant seem to figure this out in Spin
All i would like to do is be able to alternately turn on and off say 8 Led's on p1 through p9 each time i press a button on p0, it seems simple?
I am able to turn the leds on and off using the outa command but just cant wrap my head around how the button loop works in Spin. once again i apologize for the trivial question but could really use some advice !
All i would like to do is be able to alternately turn on and off say 8 Led's on p1 through p9 each time i press a button on p0, it seems simple?
I am able to turn the leds on and off using the outa command but just cant wrap my head around how the button loop works in Spin. once again i apologize for the trivial question but could really use some advice !

Comments
Depending of how you have connected your button you may need to swap the states for pressed (1) and released (0).
dira[8..1] := %11111111 select := 1 repeat outa[8..1] := select repeat until ina[0] == 1 'Wait until button pressed waitcnt(clkfreq/50 + cnt) 'debounce repeat until ina[0] == 0 'wait until button released waitcnt(clkfreq/50 + cnt) 'debounce select := select << 1 if select > 1<<8 select := 1To make a running code out of that, you need to add a PUB and declare the select variable (as long).Andy
This code is currently deployed in the Buzz Lightyear hand-stamper that will start showing up in Disney parks.
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 inputAgain, this is for a single input and will not return until the condition is met. The fun is in the last line of the loop: the debounce timing is incremented and then multiplied by the state of the pin. If the pin bounces open (0) then the timer is reset.
Thanks for share this