Fix the button code in the NeoPixie_Dust_Bag

This commit is contained in:
Neradoc 2022-02-19 07:22:07 +01:00
parent 849fa810e6
commit 1eaedd5086

View file

@ -22,13 +22,13 @@ delay_mult = 8 # Randomization multiplier, delay speed of the effect
pixels = neopixel.NeoPixel(
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
# initialize capacitive touch input
# initialize external capacitive touch pad (active high)
button = digitalio.DigitalInOut(touch_pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
button.pull = digitalio.Pull.DOWN
while True:
@ -83,19 +83,17 @@ while True:
# get the current button state
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:
# Short delay to debounce button.
time.sleep(0.020)
# Check if button is still low after debounce.
newstate = button.value
if not newstate:
# cycle to next color
showcolor += 1
if showcolor > 4:
showcolor = 0
# limit the cycle to the 5 colors
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.
oldstate = newstate