Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2021 Arofarn
3#
4# SPDX-License-Identifier: MIT
5
6import time
7
8from board import SCL, SDA
9import busio
10from adafruit_neotrellis.neotrellis import NeoTrellis
11from adafruit_neotrellis.multitrellis import MultiTrellis
12from neotrellism4 import NeoTrellisM4
13
14# Create the i2c object for the trellis
15I2C = busio.I2C(SCL, SDA)
16
17# Create the trellis. This is for a 2x2 array of TrellisM4 (first row) with
18# 2 Neotrellis (second row).
19#
20# [ NeoM4_left | NeoM4_right ]
21# neotrellis0 | neotrellis1
22
23trellim4_left = NeoTrellisM4()
24trellim4_right = NeoTrellisM4(left_part=trellim4_left)
25trelli = [
26 [trellim4_left, trellim4_right],
27 [NeoTrellis(I2C, False, addr=0x2F), NeoTrellis(I2C, False, addr=0x2E)],
28]
29
30trellis = MultiTrellis(trelli)
31
32# some color definitions
33OFF = (0, 0, 0)
34RED = (127, 0, 0)
35YELLOW = (127, 75, 0)
36GREEN = (0, 127, 0)
37CYAN = (0, 127, 127)
38BLUE = (0, 0, 127)
39PURPLE = (90, 0, 127)
40
41# this will be called when button events are received
42def blink(xcoord, ycoord, edge):
43 """Turn the LED on when a rising edge is detected or
44 turn the LED off when a falling edge is detected
45 """
46 if edge == NeoTrellis.EDGE_RISING:
47 trellis.color(xcoord, ycoord, BLUE)
48 elif edge == NeoTrellis.EDGE_FALLING:
49 trellis.color(xcoord, ycoord, OFF)
50
51
52for y in range(8):
53 for x in range(8):
54 # activate rising edge events on all keys
55 print(x, y)
56 trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
57 # activate falling edge events on all keys
58 trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
59 trellis.set_callback(x, y, blink)
60 trellis.color(x, y, PURPLE)
61 time.sleep(0.05)
62
63for y in range(8):
64 for x in range(8):
65 trellis.color(x, y, OFF)
66 time.sleep(0.05)
67
68while True:
69 # the trellis can only be read every 17 millisecons or so
70 trellis.sync()
71 time.sleep(0.02)