Exemplo n.º 1
0
# Our global state
current_step = 7 # we actually start on the last step since we increment first
# the state of the sequencer
beatset = [[False] * 8,
           [False] * 8,
           [False] * 8,
           [False] * 8,
           [False] * 8,
           [False] * 8,
           [False] * 8,
           [False] * 8]

# light up all keys at start
for y in range(8):
	for x in range(8):
		trellis.color(y, x, 0x020202)
		sleep(0.01)

midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

# --------------------------------------------------------------------------------------

buttonData = [{}, {}]  # [{key nums: data}, {key nums: midi data}]
keys = [] # [keynum] -> [1 = key data [momentary, latching]], [2 = midi data (int or tuple)]

for button in BUTTONS:
    buttonData[0].update({button[0]: button[1]})  # add key data
    #buttonData[1].update({button[0]: button[2]})  # add midi data

for keynum in range(0, 64):
    stuff = [
Exemplo n.º 2
0
#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
        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)
Exemplo n.º 3
0
print("done")
exit(0)
sleep(2)
print("off")
set_all(wait, OFF)
print("done")

while True:
    color = (random.randint(0, 50), random.randint(0,
                                                   50), random.randint(0, 50))
    # print(color)
    x = random.randint(0, sizeX - 1)
    y = random.randint(0, sizeY - 1)
    # print(x, y)
    try:
        trellis.color(x, y, color)
    except Exception as e:
        print(e)
        print("fail color")
    try:
        for ts in trelli:
            for t in ts:
                t.pixels.show()
    except Exception as e:
        print(e)
        print("fail show")
    if random.randint(0, 1) > 0:
        x = random.randint(0, sizeX - 1)
        y = random.randint(0, sizeY - 1)
        try:
            trellis.color(x, y, (0, 0, 0))
Exemplo n.º 4
0
        NeoTrellis(i2c_bus, False, addr=0x2F)
    ],
    [
        NeoTrellis(i2c_bus, False, addr=0x30),
        NeoTrellis(i2c_bus, False, addr=0x31)
    ],
]

BUTTONS = BUTTONS8x8

trellis = MultiTrellis(trelli)

# light up all keys at start
for y in range(8):
    for x in range(8):
        trellis.color(y, x, 0x020202)
        sleep(0.01)

midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

# --------------------------------------------------------------------------------------

buttonData = [{}, {}]  # [{key nums: data}, {key nums: midi data}]
keys = [
]  # [keynum] -> [1 = key data [momentary, latching]], [2 = midi data (int or tuple)]

for button in BUTTONS:
    buttonData[0].update({button[0]: button[1]})  # add key data
    #buttonData[1].update({button[0]: button[2]})  # add midi data

for keynum in range(0, 64):
Exemplo n.º 5
0
class Display(Thread):
    """docstring for Display."""
    def __init__(self, button_bus, led_bus, i2c_bus):
        Thread.__init__(self, name='Display')
        # super(Display, self).__init__()
        self.button_bus = button_bus
        self.led_bus = led_bus
        debug("Creating i2c bus")
        lcd.flash("Creating i2c bus")
        # i2c_bus = busio.I2C(SCL, SDA)
        lcd.setup_hw(i2c_bus)
        debug("i2c bus created")
        lcd.flash("i2c bus created")
        debug("Creating Trelli")
        lcd.flash("Creating Trelli")
        trelli = [[], [], [], []]
        # addrs = trellis_addresses
        # Create trelli sequentially with a slight pause between each
        for x, slice in enumerate(trellis_addresses):
            for y, addr in enumerate(slice):
                t = NeoTrellis(i2c_bus, False, addr=addr)
                t.pixels.auto_write = False
                trelli[x].append(t)
                sleep(0.1)
        debug("Linking Trelli")
        lcd.flash("Linking Trelli")
        self.trellis = MultiTrellis(trelli)

        debug("Trelli linked")
        lcd.flash("Trelli linked")
        self.grid_h = H
        self.grid_w = W
        self.state = 'play'
        self.led_matrix = [[(0, 0, 0) for x in range(w)] for y in range(h)]
        self.old_led_matrix = [[(0, 0, 0) for x in range(w)] for y in range(h)]
        button_cb = self.make_cb()
        debug("Initializing Trelli inputs")
        lcd.flash("Initializing Trelli inputs")
        for y in range(self.grid_h):
            for x in range(self.grid_w):
                sleep(0.01)
                self.trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
                sleep(0.01)
                self.trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
                self.trellis.set_callback(x, y, button_cb)
        self.ins_button = digitalio.DigitalInOut(D13)
        self.gbl_button = digitalio.DigitalInOut(D6)
        debug("Inputs initialized")
        lcd.flash("Inputs initialized")
        self.col_scheme = select_scheme('default')
        return

    def run(self):
        debug("Display thread started")
        while True:
            sleep(0.01)
            m = self.get_cmds()
            if m.get('cmd') != None:
                debug(m)
                self.button_bus.put(m)
            if not self.led_bus.empty():
                status, led_grid = self.led_bus.get()
                self.draw_all(status, led_grid)

        return

    def read_gbl_button(self):
        return not self.gbl_button.value

    def read_ins_button(self):
        return not self.ins_button.value

    def get_cmds(self):
        try:
            self.trellis.sync()  # TODO undo? Fails if called too often
        except Exception as e:
            debug("HW error: {}".format(str(e)))
        m = {'cmd': None}
        if self.read_gbl_button():
            if self.state != 'gbl_cfg':
                m['cmd'] = "CONFIG_A"
                self.state = 'gbl_cfg'
            else:
                self.state = 'play'
        elif self.read_ins_button():
            if self.state != 'ins_cfg':
                m['cmd'] = "CONFIG_B"
                self.state = 'ins_cfg'
            else:
                self.state = 'play'
        return m

    def draw_all(self, status, led_grid):
        self.draw_note_grid(led_grid)
        self.redraw_diff()
        return

    def blank_screen(self):
        for x in range(len(self.led_matrix)):
            for y in range(len(self.led_matrix[x])):
                self.led_matrix[x][y] = OFF

    def redraw_diff(self):
        diffs = []
        for x in range(len(self.led_matrix)):
            for y in range(len(self.led_matrix[x])):
                if self.led_matrix[x][y] != self.old_led_matrix[x][y]:
                    diffs.append((x, y, self.led_matrix[x][y]))
                self.old_led_matrix[x][y] = self.led_matrix[x][y]
        for diff in diffs:
            self.trellis.color(diff[0], diff[1], diff[2])
            sleep(0.001)
        if len(diffs) > 0:
            if not AUTO_WRITE:
                for ts in self.trellis._trelli:
                    for t in ts:
                        t.pixels.show()
        return

    def draw_note_grid(self, led_grid):
        for x in range(len(led_grid)):
            for y in range(len(led_grid[x])):
                color = self.col_scheme.get_color(led_grid[x][y], x, y)
                # col = c.PALLETE[led_grid[x][y]]
                self.led_matrix[x][self.grid_h - 1 - y] = color
        return

    def make_cb(self):
        def button_cb(xcoord, ycoord, edge):
            if edge == NeoTrellis.EDGE_RISING:
                self.button_bus.put({
                    'cmd': 'note',
                    'x': xcoord,
                    'y': self.grid_h - 1 - ycoord
                })
            return

        return button_cb

    def draw_load_screen(self):
        return
Exemplo n.º 6
0
class Trellis(ActorThread):
    """Physical Trellis hardware"""
    def __init__(self, i2c_bus):
        super().__init__()
        self.led_matrix = [[BLANK for x in range(W)] for y in range(H)]
        self.old_led_matrix = [[BLANK for x in range(W)] for y in range(H)]
        self.trelli = [[] for i in range(int(H/4))]  # [[],[]]
        print("Creating Trelli")
        for x, slice in enumerate(trellis_addresses):
            for y, addr in enumerate(slice):
                t = NeoTrellis(i2c_bus, False, addr=addr)
                t.pixels.auto_write = False
                self.trelli[x].append(t)
                sleep(0.1)
                pass
        print("Linking Trelli")
        self.trellis = MultiTrellis(self.trelli)
        print("Trelli linked")
        button_cb = self.make_button_cb()
        print("Initializing Trelli inputs")
        for y in range(H):
            for x in range(W):
                pass
                sleep(0.01)
                self.trellis.activate_key(x, y, NeoTrellis.EDGE_RISING)
                sleep(0.01)
                self.trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING)
                self.trellis.set_callback(x, y, button_cb)
        debug("Inputs initialized")
        self.blank_screen()

    def make_button_cb(self):
        def button_cb(xcoord, ycoord, edge):
            if edge == NeoTrellis.EDGE_RISING:
                post('button_grid', {'event': 'press', 'x': xcoord, 'y': H-1-ycoord})
            elif edge == NeoTrellis.EDGE_FALLING:
                post('button_grid', {'event': 'release', 'x': xcoord, 'y': H-1-ycoord})
            return
        return button_cb

    def blank_screen(self):
        self.cb_draw_grid({'led_grid': [[BLANK for x in range(W)] for y in range(H)]})

    def cb_draw_grid(self, msg):
        led_grid = msg['led_grid']
        diffs = []
        for x in range(len(self.old_led_matrix)):
            for y in range(len(self.old_led_matrix[x])):
                if led_grid[x][y] != self.old_led_matrix[x][y]:
                    col = led_grid[x][y]
                    diffs.append((x, y, col))
                    self.old_led_matrix[x][y] = col 
                    self.trellis.color(diff[0], diff[1], diff[2])
                    sleep(0.001)
                                    # for diff in diffs:
                                        # self.trellis.color(diff[0], diff[1], diff[2])
                                        # sleep(0.001)
        if len(diffs) > 0:
            if not AUTO_WRITE:
                for x, y in boards_to_update(diffs):
                    pass
                    self.trellis._trelli[x][y].pixels.show()
                                        # for ts in self.trellis._trelli:
                                        #     for t in ts:
                                        #         t.pixels.show()
        return


    def cb_anymsg(self, msg):
        self.cb_draw_grid(msg)
        return
Exemplo n.º 7
0
PURPLE = (180, 0, 255)

#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
        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)