Skip to content

Commit 17e3cac

Browse files
committed
updated trellis_simpletest example
1 parent b1ecb80 commit 17e3cac

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

examples/trellis_simpletest.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Create the I2C interface
1414
i2c = busio.I2C(SCL, SDA)
1515

16-
# Create a Trellis object for each board
16+
# Create a Trellis object
1717
trellis = Trellis(i2c) # 0x70 when no I2C address is supplied
1818

1919
# 'auto_show' defaults to 'True', so anytime LED states change,
@@ -23,12 +23,12 @@
2323

2424
# Turn on every LED
2525
print('Turning all LEDs on...')
26-
trellis.fill(1)
26+
trellis.led.fill(True)
2727
time.sleep(2)
2828

2929
# Turn off every LED
3030
print('Turning all LEDs off...')
31-
trellis.fill(0)
31+
trellis.led.fill(False)
3232
time.sleep(2)
3333

3434
# Turn on every LED, one at a time
@@ -44,34 +44,28 @@
4444
time.sleep(.1)
4545

4646
# Now start reading button activity
47-
# When a button is depressed (just_pressed),
48-
# the LED for that button will turn on.
49-
# When the button is relased (released),
50-
# the LED will turn off.
51-
# Any button that is still depressed (pressed_buttons),
52-
# the LED will remain on.
47+
# - When a button is depressed (just_pressed),
48+
# the LED for that button will turn on.
49+
# - When the button is relased (released),
50+
# the LED will turn off.
51+
# - Any button that is still depressed (pressed_buttons),
52+
# the LED will remain on.
5353
print('Starting button sensory loop...')
5454
pressed_buttons = set()
5555
while True:
5656
# Make sure to take a break during each trellis.read_buttons
5757
# cycle.
5858
time.sleep(.1)
5959

60-
try:
61-
just_pressed, released = trellis.read_buttons()
62-
for b in just_pressed:
63-
print('pressed:', b)
64-
trellis.led[b] = True
65-
pressed_buttons.update(just_pressed)
66-
for b in released:
67-
print('released:', b)
68-
trellis.led[b] = False
69-
pressed_buttons.difference_update(released)
70-
for b in pressed_buttons:
71-
print('still pressed:', b)
72-
trellis.led[b] = True
73-
74-
# This allows the program to stop running when Ctrl+C is
75-
# pressed in the REPL.
76-
except KeyboardInterrupt:
77-
break
60+
just_pressed, released = trellis.read_buttons()
61+
for b in just_pressed:
62+
print('pressed:', b)
63+
trellis.led[b] = True
64+
pressed_buttons.update(just_pressed)
65+
for b in released:
66+
print('released:', b)
67+
trellis.led[b] = False
68+
pressed_buttons.difference_update(released)
69+
for b in pressed_buttons:
70+
print('still pressed:', b)
71+
trellis.led[b] = True

0 commit comments

Comments
 (0)