I was thinking before the while loop to setup the events of a short or long press.
This thing is pretty simple.
Short button press changes on board dot led color (red, green, blue)
Long button press increase dim level 0.1 per 0.5sec to 1, then back to 0.2
I eventually want to make this shutdown and go to low power after 30 minutes and wake back up on a button press.
trying to create the events for short and long button press is what really has me hung up at the moment. That and the color change off the short press.....
On the color change I thought that it would be able to count through the list. Some previous revision I had it run through the three once I pushed the button, but I could not get it to increment through each push.
Does anyone have any ideas on how to approach this ? Thanks!!
Code: Select all
import board
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogOut, AnalogIn
import touchio
import adafruit_dotstar as dotstar
import time
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
dot.brightness = 0.2
def countup():
global counter
counter1 = (counter1 + 1) % len(LEDC)
coutner2 = (counter2 + 0.1) % len(dot.brightness)
counter1 = 0
counter2 = 0.2
LEDC = ["RED, GRN, BLU"]
RED = (255, 0, 0)
GRN = (0, 255, 0)
BLU = (0, 0, 255)
analog1in = AnalogIn(board.D0)
aout = AnalogOut(board.D1)
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP
touch1 = touchio.TouchIn(board.D3)
touch2 = touchio.TouchIn(board.D1)
countup()
while True:
if touch1.value: # short button press <0.5 sec
counter1 += 1
print(counter1)
print(LEDC[counter1])
# I am trying to get this to cycle through the colors ( RED, GRN, BLU)
LEDC[counter]()
dot[0] = counter1
time.sleep(0.2)
if touch1.value: # long button press >1 sec
counter2 += 1 # I think this needs be be different counter for dim
print(DIM[counter2])
DIM[counter2]()
DIM(dot.brightness)
# increase dim 0.1 for each 0.5 sec button is pushed