Skip to content

Commit 8116cfe

Browse files
authored
Merge pull request #2027 from Neradoc/neopixel-pixie-dust-bag
Fix the button code in the NeoPixie_Dust_Bag
2 parents 489d06c + ab7dbdb commit 8116cfe

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

NeoPixie_Dust_Bag/code.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
pixels = neopixel.NeoPixel(
2323
neo_pin, pixel_count, brightness=.4, auto_write=False)
2424

25-
oldstate = True # counting touch sensor button pushes
25+
oldstate = False # counting touch sensor button pushes
2626
showcolor = 0 # color mode for cycling
2727

28-
# initialize capacitive touch input
28+
# initialize external capacitive touch pad (active high)
2929
button = digitalio.DigitalInOut(touch_pin)
3030
button.direction = digitalio.Direction.INPUT
3131
button.pull = digitalio.Pull.UP
@@ -83,19 +83,17 @@
8383
# get the current button state
8484
newstate = button.value
8585

86-
# Check if state changed from high to low (button press).
86+
# Check if state changed from low to high (button/touchpad press).
8787
if newstate and not oldstate:
88-
# Short delay to debounce button.
89-
time.sleep(0.020)
90-
91-
# Check if button is still low after debounce.
92-
newstate = button.value
93-
94-
if not newstate:
88+
# cycle to next color
9589
showcolor += 1
9690

97-
if showcolor > 4:
98-
showcolor = 0
91+
# limit the cycle to the 5 colors
92+
if showcolor > 4:
93+
showcolor = 0
94+
95+
# give feedback to the REPL to debug the touch pad
96+
# print("Color:", showcolor)
9997

10098
# Set the last button state to the old state.
10199
oldstate = newstate

0 commit comments

Comments
 (0)