Fix the button code in the NeoPixie_Dust_Bag
This commit is contained in:
parent
849fa810e6
commit
1eaedd5086
1 changed files with 11 additions and 13 deletions
|
|
@ -22,13 +22,13 @@ delay_mult = 8 # Randomization multiplier, delay speed of the effect
|
||||||
pixels = neopixel.NeoPixel(
|
pixels = neopixel.NeoPixel(
|
||||||
neo_pin, pixel_count, brightness=.4, auto_write=False)
|
neo_pin, pixel_count, brightness=.4, auto_write=False)
|
||||||
|
|
||||||
oldstate = True # counting touch sensor button pushes
|
oldstate = False # counting touch sensor button pushes
|
||||||
showcolor = 0 # color mode for cycling
|
showcolor = 0 # color mode for cycling
|
||||||
|
|
||||||
# initialize capacitive touch input
|
# initialize external capacitive touch pad (active high)
|
||||||
button = digitalio.DigitalInOut(touch_pin)
|
button = digitalio.DigitalInOut(touch_pin)
|
||||||
button.direction = digitalio.Direction.INPUT
|
button.direction = digitalio.Direction.INPUT
|
||||||
button.pull = digitalio.Pull.UP
|
button.pull = digitalio.Pull.DOWN
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
|
@ -83,19 +83,17 @@ while True:
|
||||||
# get the current button state
|
# get the current button state
|
||||||
newstate = button.value
|
newstate = button.value
|
||||||
|
|
||||||
# Check if state changed from high to low (button press).
|
# Check if state changed from low to high (button/touchpad press).
|
||||||
if newstate and not oldstate:
|
if newstate and not oldstate:
|
||||||
# Short delay to debounce button.
|
# cycle to next color
|
||||||
time.sleep(0.020)
|
|
||||||
|
|
||||||
# Check if button is still low after debounce.
|
|
||||||
newstate = button.value
|
|
||||||
|
|
||||||
if not newstate:
|
|
||||||
showcolor += 1
|
showcolor += 1
|
||||||
|
|
||||||
if showcolor > 4:
|
# limit the cycle to the 5 colors
|
||||||
showcolor = 0
|
if showcolor > 4:
|
||||||
|
showcolor = 0
|
||||||
|
|
||||||
|
# give feedback to the REPL to debug the touch pad
|
||||||
|
# print("Color:", showcolor)
|
||||||
|
|
||||||
# Set the last button state to the old state.
|
# Set the last button state to the old state.
|
||||||
oldstate = newstate
|
oldstate = newstate
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue