From 1eaedd508623ed6ebf2a9bb7b60aaa19179eadc6 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Sat, 19 Feb 2022 07:22:07 +0100 Subject: [PATCH 1/2] Fix the button code in the NeoPixie_Dust_Bag --- NeoPixie_Dust_Bag/code.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/NeoPixie_Dust_Bag/code.py b/NeoPixie_Dust_Bag/code.py index cf704130b..baab79f47 100644 --- a/NeoPixie_Dust_Bag/code.py +++ b/NeoPixie_Dust_Bag/code.py @@ -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 From ab7dbdb23c956f2e3245d765b761722cd3e64617 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Sat, 19 Feb 2022 20:13:48 +0100 Subject: [PATCH 2/2] pull up in case no pull down --- NeoPixie_Dust_Bag/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NeoPixie_Dust_Bag/code.py b/NeoPixie_Dust_Bag/code.py index baab79f47..f911cf257 100644 --- a/NeoPixie_Dust_Bag/code.py +++ b/NeoPixie_Dust_Bag/code.py @@ -28,7 +28,7 @@ showcolor = 0 # color mode for cycling # initialize external capacitive touch pad (active high) button = digitalio.DigitalInOut(touch_pin) button.direction = digitalio.Direction.INPUT -button.pull = digitalio.Pull.DOWN +button.pull = digitalio.Pull.UP while True: