|
13 | 13 | # Create the I2C interface
|
14 | 14 | i2c = busio.I2C(SCL, SDA)
|
15 | 15 |
|
16 |
| -# Create a Trellis object for each board |
| 16 | +# Create a Trellis object |
17 | 17 | trellis = Trellis(i2c) # 0x70 when no I2C address is supplied
|
18 | 18 |
|
19 | 19 | # 'auto_show' defaults to 'True', so anytime LED states change,
|
|
23 | 23 |
|
24 | 24 | # Turn on every LED
|
25 | 25 | print('Turning all LEDs on...')
|
26 |
| -trellis.fill(1) |
| 26 | +trellis.led.fill(True) |
27 | 27 | time.sleep(2)
|
28 | 28 |
|
29 | 29 | # Turn off every LED
|
30 | 30 | print('Turning all LEDs off...')
|
31 |
| -trellis.fill(0) |
| 31 | +trellis.led.fill(False) |
32 | 32 | time.sleep(2)
|
33 | 33 |
|
34 | 34 | # Turn on every LED, one at a time
|
|
44 | 44 | time.sleep(.1)
|
45 | 45 |
|
46 | 46 | # 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. |
53 | 53 | print('Starting button sensory loop...')
|
54 | 54 | pressed_buttons = set()
|
55 | 55 | while True:
|
56 | 56 | # Make sure to take a break during each trellis.read_buttons
|
57 | 57 | # cycle.
|
58 | 58 | time.sleep(.1)
|
59 | 59 |
|
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