neotrellis_multitrellis_simpletest.py
1 import time 2 3 from board import SCL, SDA 4 import busio 5 from adafruit_neotrellis.neotrellis import NeoTrellis 6 from adafruit_neotrellis.multitrellis import MultiTrellis 7 8 # create the i2c object for the trellis 9 i2c_bus = busio.I2C(SCL, SDA) 10 11 """create the trellis. This is for a 2x2 array of NeoTrellis boards 12 for a 2x1 array (2 boards connected left to right) you would use: 13 14 trelli = [ 15 [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)] 16 ] 17 18 """ 19 trelli = [ 20 [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)], 21 [NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)], 22 ] 23 24 trellis = MultiTrellis(trelli) 25 26 # some color definitions 27 OFF = (0, 0, 0) 28 RED = (255, 0, 0) 29 YELLOW = (255, 150, 0) 30 GREEN = (0, 255, 0) 31 CYAN = (0, 255, 255) 32 BLUE = (0, 0, 255) 33 PURPLE = (180, 0, 255) 34 35 # this will be called when button events are received 36 def blink(xcoord, ycoord, edge): 37 # turn the LED on when a rising edge is detected 38 if edge == NeoTrellis.EDGE_RISING: 39 trellis.color(xcoord, ycoord, BLUE) 40 # turn the LED off when a rising edge is detected 41 elif edge == NeoTrellis.EDGE_FALLING: 42 trellis.color(xcoord, ycoord, OFF) 43 44 45 for y in range(8): 46 for x in range(8): 47 # activate rising edge events on all keys 48 trellis.activate_key(x, y, NeoTrellis.EDGE_RISING) 49 # activate falling edge events on all keys 50 trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING) 51 trellis.set_callback(x, y, blink) 52 trellis.color(x, y, PURPLE) 53 time.sleep(0.05) 54 55 for y in range(8): 56 for x in range(8): 57 trellis.color(x, y, OFF) 58 time.sleep(0.05) 59 60 while True: 61 # the trellis can only be read every 17 millisecons or so 62 trellis.sync() 63 time.sleep(0.02)