Update code.py
linting whitespace
This commit is contained in:
parent
6fe09719b8
commit
4ca72a8231
1 changed files with 8 additions and 8 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
# Simple paint program for Trellis M4 Express
|
# Simple paint program for Trellis M4 Express
|
||||||
# Press any button it will cycle through a palette of colors!
|
# Press any button it will cycle through a palette of colors!
|
||||||
#
|
#
|
||||||
# Mike Barela for Adafruit Industries November, 2018
|
# Mike Barela for Adafruit Industries November, 2018
|
||||||
#
|
#
|
||||||
import time
|
import time
|
||||||
import adafruit_trellism4
|
import adafruit_trellism4
|
||||||
|
|
||||||
trellis = adafruit_trellism4.TrellisM4Express()
|
trellis = adafruit_trellism4.TrellisM4Express()
|
||||||
|
|
||||||
# See https://www.w3schools.com/colors/colors_picker.asp
|
# See https://www.w3schools.com/colors/colors_picker.asp
|
||||||
|
|
@ -26,27 +26,27 @@ BLACK = 0x000000
|
||||||
|
|
||||||
color_cycle = [BLACK, RED, ORANGE, YELLOW, OLIVE, GREEN, AQUA,
|
color_cycle = [BLACK, RED, ORANGE, YELLOW, OLIVE, GREEN, AQUA,
|
||||||
TEAL, BLUE, NAVY, MAROON, PURPLE, PINK, WHITE]
|
TEAL, BLUE, NAVY, MAROON, PURPLE, PINK, WHITE]
|
||||||
|
|
||||||
colors = 13 # Number of colors in color_cycle
|
colors = 13 # Number of colors in color_cycle
|
||||||
|
|
||||||
key_state = [0 for _ in range(32)] # All keys are color 0 (BLACK)
|
key_state = [0 for _ in range(32)] # All keys are color 0 (BLACK)
|
||||||
|
|
||||||
trellis.pixels.fill(BLACK) # Turn off all pixels
|
trellis.pixels.fill(BLACK) # Turn off all pixels
|
||||||
|
|
||||||
current_press = set()
|
current_press = set()
|
||||||
while True:
|
while True:
|
||||||
pressed = set(trellis.pressed_keys)
|
pressed = set(trellis.pressed_keys)
|
||||||
for press in pressed - current_press:
|
for press in pressed - current_press:
|
||||||
if press:
|
if press:
|
||||||
print("Pressed:", press)
|
print("Pressed:", press)
|
||||||
x, y = press
|
x, y = press
|
||||||
pixel = (press[1] * 8) + press[0]
|
pixel = (press[1] * 8) + press[0]
|
||||||
if key_state[pixel] == colors: # If we're at white
|
if key_state[pixel] == colors: # If we're at white
|
||||||
key_state[pixel] = 0 # Set back to black
|
key_state[pixel] = 0 # Set back to black
|
||||||
else:
|
else:
|
||||||
key_state[pixel] += 1 # Use next color
|
key_state[pixel] += 1 # Use next color
|
||||||
# Change the pushed pixel to the next color
|
# Change the pushed pixel to the next color
|
||||||
trellis.pixels[x, y] = color_cycle[key_state[pixel]]
|
trellis.pixels[x, y] = color_cycle[key_state[pixel]]
|
||||||
|
|
||||||
time.sleep(0.08)
|
time.sleep(0.08)
|
||||||
current_press = pressed
|
current_press = pressed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue