Init commit

This commit is contained in:
Pierrick C
2019-06-16 16:32:15 +02:00
commit 4388b001d5
17 changed files with 1488 additions and 0 deletions

View File

@ -0,0 +1,65 @@
import time
from board import SCL, SDA
import busio
from adafruit_neotrellis.neotrellism4 import NeoTrellisM4
from adafruit_neotrellis.neotrellis import NeoTrellis
from adafruit_neotrellis.multitrellis import MultiTrellis
#create the i2c object for the trellis
I2C = busio.I2C(SCL, SDA)
"""create the trellis. This is for a 2x2 array of TrellisM4 (first row) with
2 Neotrellis (second row).
[ NeoM4_left | NeoM4_right ]
neotrellis0 | neotrellis1
"""
trellim4_left = NeoTrellisM4()
trellim4_right = NeoTrellisM4(left_part=trellim4_left)
trelli = [
[trellim4_left, trellim4_right],
[NeoTrellis(I2C, False, addr=0x2F), NeoTrellis(I2C, False, addr=0x2E)]
]
trellis = MultiTrellis(trelli)
#some color definitions
OFF = (0, 0, 0)
RED = (127, 0, 0)
YELLOW = (127, 75, 0)
GREEN = (0, 127, 0)
CYAN = (0, 127, 127)
BLUE = (0, 0, 127)
PURPLE = (90, 0, 127)
#this will be called when button events are received
def blink(xcoord, ycoord, edge):
#turn the LED on when a rising edge is detected
if edge == NeoTrellis.EDGE_RISING:
trellis.color(xcoord, ycoord, BLUE)
#turn the LED off when a rising edge is detected
elif edge == NeoTrellis.EDGE_FALLING:
trellis.color(xcoord, ycoord, OFF)
for y in range(8):
for x in range(8):
#activate rising edge events on all keys
print(x, y)
trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
#activate falling edge events on all keys
trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
trellis.set_callback(x, y, blink)
trellis.color(x, y, PURPLE)
time.sleep(.05)
for y in range(8):
for x in range(8):
trellis.color(x, y, OFF)
time.sleep(.05)
while True:
#the trellis can only be read every 17 millisecons or so
trellis.sync()
time.sleep(.02)

View File

@ -0,0 +1,68 @@
import time
from adafruit_neotrellis.neotrellism4 import NeoTrellisM4
#create the trellis
trellis_left = NeoTrellisM4()
trellis_right = NeoTrellisM4(left_part=trellis_left)
#some color definitions
OFF = (0, 0, 0)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
#this will be called when button events are received
def blink(event):
#turn the LED on when a rising edge is detected
if event.edge == NeoTrellisM4.EDGE_RISING:
trellis_left.pixels[event.number] = CYAN
#turn the LED off when a rising edge is detected
elif event.edge == NeoTrellisM4.EDGE_FALLING:
trellis_left.pixels[event.number] = OFF
for i in range(16):
#activate rising edge events on all keys
trellis_left.activate_key(i, NeoTrellisM4.EDGE_RISING)
#activate falling edge events on all keys
trellis_left.activate_key(i, NeoTrellisM4.EDGE_FALLING)
#set all keys to trigger the blink callback
trellis_left.callbacks[i] = blink
#cycle the LEDs on startup
trellis_left.pixels[i] = PURPLE
time.sleep(.05)
for i in range(16):
trellis_left.pixels[i] = OFF
time.sleep(.05)
for i in range(16):
#activate rising edge events on all keys
trellis_right.activate_key(i, NeoTrellisM4.EDGE_RISING)
#activate falling edge events on all keys
trellis_right.activate_key(i, NeoTrellisM4.EDGE_FALLING)
#set all keys to trigger the blink callback
trellis_right.callbacks[i] = blink
#cycle the LEDs on startup
trellis_right.pixels[i] = PURPLE
time.sleep(.05)
for i in range(16):
trellis_right.pixels[i] = OFF
time.sleep(.05)
#print(trellis.callbacks)
time.sleep(2)
while True:
#call the sync function call any triggered callbacks
trellis_left.sync()
trellis_right.sync()
#the trellis can only be read every 17 millisecons or so
time.sleep(.02)