Simple test¶
Ensure your device works with this simple test.
examples/neotrellis_simpletest.py¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6from board import SCL, SDA
7import busio
8from adafruit_neotrellis.neotrellis import NeoTrellis
9
10# create the i2c object for the trellis
11i2c_bus = busio.I2C(SCL, SDA)
12
13# create the trellis
14trellis = NeoTrellis(i2c_bus)
15
16# some color definitions
17OFF = (0, 0, 0)
18RED = (255, 0, 0)
19YELLOW = (255, 150, 0)
20GREEN = (0, 255, 0)
21CYAN = (0, 255, 255)
22BLUE = (0, 0, 255)
23PURPLE = (180, 0, 255)
24
25# this will be called when button events are received
26def blink(event):
27 # turn the LED on when a rising edge is detected
28 if event.edge == NeoTrellis.EDGE_RISING:
29 trellis.pixels[event.number] = CYAN
30 # turn the LED off when a falling edge is detected
31 elif event.edge == NeoTrellis.EDGE_FALLING:
32 trellis.pixels[event.number] = OFF
33
34
35for i in range(16):
36 # activate rising edge events on all keys
37 trellis.activate_key(i, NeoTrellis.EDGE_RISING)
38 # activate falling edge events on all keys
39 trellis.activate_key(i, NeoTrellis.EDGE_FALLING)
40 # set all keys to trigger the blink callback
41 trellis.callbacks[i] = blink
42
43 # cycle the LEDs on startup
44 trellis.pixels[i] = PURPLE
45 time.sleep(0.05)
46
47for i in range(16):
48 trellis.pixels[i] = OFF
49 time.sleep(0.05)
50
51while True:
52 # call the sync function call any triggered callbacks
53 trellis.sync()
54 # the trellis can only be read every 17 millisecons or so
55 time.sleep(0.02)
MultiTrellis test¶
The multitrellis submodule helps manage multiple trellis as one.
examples/neotrellis_multitrellis_simpletest.py¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6from board import SCL, SDA
7import busio
8from adafruit_neotrellis.neotrellis import NeoTrellis
9from adafruit_neotrellis.multitrellis import MultiTrellis
10
11# create the i2c object for the trellis
12i2c_bus = busio.I2C(SCL, SDA)
13
14"""create the trellis. This is for a 2x2 array of NeoTrellis boards
15for a 2x1 array (2 boards connected left to right) you would use:
16
17trelli = [
18 [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)]
19 ]
20
21"""
22trelli = [
23 [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)],
24 [NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)],
25]
26
27trellis = MultiTrellis(trelli)
28
29# some color definitions
30OFF = (0, 0, 0)
31RED = (255, 0, 0)
32YELLOW = (255, 150, 0)
33GREEN = (0, 255, 0)
34CYAN = (0, 255, 255)
35BLUE = (0, 0, 255)
36PURPLE = (180, 0, 255)
37
38# this will be called when button events are received
39def blink(xcoord, ycoord, edge):
40 # turn the LED on when a rising edge is detected
41 if edge == NeoTrellis.EDGE_RISING:
42 trellis.color(xcoord, ycoord, BLUE)
43 # turn the LED off when a falling edge is detected
44 elif edge == NeoTrellis.EDGE_FALLING:
45 trellis.color(xcoord, ycoord, OFF)
46
47
48for y in range(8):
49 for x in range(8):
50 # activate rising edge events on all keys
51 trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
52 # activate falling edge events on all keys
53 trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
54 trellis.set_callback(x, y, blink)
55 trellis.color(x, y, PURPLE)
56 time.sleep(0.05)
57
58for y in range(8):
59 for x in range(8):
60 trellis.color(x, y, OFF)
61 time.sleep(0.05)
62
63while True:
64 # the trellis can only be read every 17 millisecons or so
65 trellis.sync()
66 time.sleep(0.02)