Merge pull request #2027 from Neradoc/neopixel-pixie-dust-bag

Fix the button code in the NeoPixie_Dust_Bag
This commit is contained in:
Limor "Ladyada" Fried 2022-02-22 13:46:13 -05:00 committed by GitHub
commit 8116cfe7c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,10 +22,10 @@ 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
@ -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