Skip to content

Commit

Permalink
Prevent RGB LED from annoyingly blinking when touchwheel on badge
Browse files Browse the repository at this point in the history
Added a state array for wheel and buttons to update
Now code writes the overall state each loop rather than for button then wheel separately.
  • Loading branch information
baileysage committed Nov 1, 2024
1 parent 63f5317 commit 0a158bb
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions software/software/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import time

counter = 0
# Extraneous beginning byte so I don't have to re-index
led_state = bytearray(9)

## do a quick spiral to test
if petal_bus:
Expand All @@ -19,44 +21,42 @@
## display button status on RGB
if petal_bus:
if not buttonA.value():
petal_bus.writeto_mem(PETAL_ADDRESS, 2, bytes([0x80]))
led_state[2] = led_state[2] | 0x80
else:
petal_bus.writeto_mem(PETAL_ADDRESS, 2, bytes([0x00]))
led_state[2] = led_state[2] & 0x7F

if not buttonB.value():
petal_bus.writeto_mem(PETAL_ADDRESS, 3, bytes([0x80]))
led_state[3] = led_state[3] | 0x80
else:
petal_bus.writeto_mem(PETAL_ADDRESS, 3, bytes([0x00]))
led_state[3] = led_state[3] & 0x7F

if not buttonC.value():
petal_bus.writeto_mem(PETAL_ADDRESS, 4, bytes([0x80]))
led_state[4] = led_state[4] | 0x80
else:
petal_bus.writeto_mem(PETAL_ADDRESS, 4, bytes([0x00]))
led_state[4] = led_state[4] & 0x7F

## see what's going on with the touch wheel
if touchwheel_bus:
tw = touchwheel_read(touchwheel_bus)

## display touchwheel on petal
if petal_bus and touchwheel_bus:
if tw > 0:
tw = (128 - tw) % 256
petal = int(tw/32) + 1
else:
petal = 999
if petal_bus:
if touchwheel_bus:
if tw > 0:
tw = (128 - tw) % 256
petal = int(tw/32) + 1
else:
petal = 999
for i in range(1,9):
if i == petal:
led_state[i] = led_state[i] | 0x7F
else:
led_state[i] = led_state[i] & 0x80

# Write updated values to board.
for i in range(1,9):
if i == petal:
petal_bus.writeto_mem(0, i, bytes([0x7F]))
else:
petal_bus.writeto_mem(0, i, bytes([0x00]))



petal_bus.writeto_mem(PETAL_ADDRESS, i, bytes([led_state[i]]))

time.sleep_ms(20)
bootLED.off()






0 comments on commit 0a158bb

Please sign in to comment.