def main(): trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((0, 0, 0)) trellis.pixels.auto_write = False btns = buttons.Buttons(trellis) config = {} try: with open('quickstart_config.csv', 'r') as f: lines = f.readlines() for line in lines: if len(line) <= 4: continue x, y, mod = line[0], line[2], line[4:] if not x.isdigit() or not y.isdigit(): continue x = max(0, min(7, int(x))) y = max(0, min(3, int(y))) mod = ''.join(list(filter(str.isalpha, mod))) if (len(mod) == 0): continue config[(x, y)] = mod except OSError: with open('quickstart_config.csv', 'w') as f: pass if (len(config) == 0): config[(0, 0)] = 'module_list' for p, mod in config.items(): random.seed(hash(mod)) c = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) print(p, c) trellis.pixels[p] = c trellis.pixels.show() available = set(config.keys()) s = frozenset() while len(s) == 0: btns.update() s = btns.pressed() & available time.sleep(0.01) trellis.pixels.auto_write = True deinit_trellis.deinit(trellis) p = s.pop() mod = config[p] print('import ' + mod) mod = __import__(mod) if 'main' in dir(mod): print(mod.__name__ + '.main') mod.main()
def main(): trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((0, 0, 0)) trellis.pixels.auto_write = False while len(trellis.pressed_keys) > 0: time.sleep(0.01) timer = time.monotonic() t = 0 while len(trellis.pressed_keys) == 0: i = int(100 * (-math.cos(2 * math.pi * t) * 0.5 + 0.5)**2) c = (i, i, i) trellis.pixels[0, 0] = c trellis.pixels[7, 0] = c trellis.pixels[0, 3] = c trellis.pixels[7, 3] = c trellis.pixels.show() time.sleep(0.01) t = time.monotonic() - timer audio = audioio.AudioOut(board.A1, right_channel=board.A0) f = open('tuba_fanfare.wav', 'rb') wav = audioio.WaveFile(f) audio.play(wav) timer = time.monotonic() t = 0 m = 0.25 while t < 2: p = t / 2.0 + 0.1 for x in range(8): for y in range(4): d = 1 - (abs(x - 3.5) + abs(y - 1.5)) / 5 v = p + m * (p - d) v = max(0, min(2, 2 * v)) v = 1 - abs(1 - v) i = int(100 * v**3) trellis.pixels[x, y] = (i, i, i) trellis.pixels.show() time.sleep(0.01) t = time.monotonic() - timer audio.deinit() deinit_trellis.deinit(trellis) __import__('start').main()
def main(): SRC_FOLDER = 'drum_sounds/' sounds = { (0, 0): 'kick.wav', (1, 0): 'snare.wav', (2, 0): 'hihat_l.wav', (3, 0): 'hihat_s.wav', (0, 1): 'coin.wav', (1, 1): 'bass_wha_c.wav', (2, 1): 'blip_c.wav', (3, 1): 'clap.wav', } colors = { (0, 0): (100, 0, 0), (1, 0): (100, 100, 0), (2, 0): (0, 75, 50), (3, 0): (0, 0, 125), (0, 1): (100, 25, 0), (1, 1): (100, 0, 100), (2, 1): (50, 50, 50), (3, 1): (0, 100, 0), } trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.auto_write = False audio = audioio.AudioOut(board.A1, right_channel=board.A0) def play_wav(fname, async=False): try: length = os.stat(fname)[6] f = open(fname, "rb") wav = audioio.WaveFile(f) duration = length / (wav.sample_rate * wav.channel_count * wav.bits_per_sample / 8) audio.play(wav) if async: return duration while audio.playing: time.sleep(0.01) audio.stop() except OSError: print('could not find ' + fname)
All text above must be included in any redistribution. """ # pylint: disable=wildcard-import,unused-wildcard-import,eval-used import time import board import audioio import audiocore import audiomixer import adafruit_trellism4 from color_names import * # Our keypad + neopixel driver trellis = adafruit_trellism4.TrellisM4Express(rotation=0) SELECTED_COLOR = WHITE # the color for the selected sample SAMPLE_FOLDER = '/samples/' # the name of the folder containing the samples SAMPLES = [] BLACK = 0x000000 # load the sound & color specifications with open('soundboard.txt', 'r') as f: for line in f: cleaned = line.strip() if len(cleaned) > 0 and cleaned[0] != '#': if cleaned == 'pass': SAMPLES.append(('does_not_exist.wav', BLACK)) else: f_name, color = cleaned.split(',', 1)
"""Test your Trellis M4 Express without needing the serial output. Press any button and the rest will light up the same color!""" import time import adafruit_trellism4 trellis = adafruit_trellism4.TrellisM4Express() def wheel(pos): if pos < 0 or pos > 255: return 0, 0, 0 if pos < 85: return int(255 - pos * 3), int(pos * 3), 0 if pos < 170: pos -= 85 return 0, int(255 - pos * 3), int(pos * 3) pos -= 170 return int(pos * 3), 0, int(255 - (pos * 3)) for x in range(trellis.pixels.width): for y in range(trellis.pixels.height): pixel_index = ((y * 8) + x) * 256 // 32 trellis.pixels[x, y] = wheel(pixel_index & 255) current_press = set() while True: pressed = set(trellis.pressed_keys) for press in pressed - current_press: if press: print("Pressed:", press)
# Once asleep, how much time to wait between "snores" which fade up and down one button. SNORE_PAUSE = 0.5 # Time in seconds to take fading up the snoring LED. SNORE_UP = 2 # Time in seconds to take fading down the snoring LED. SNORE_DOWN = 1 TOTAL_SNORE = SNORE_PAUSE + SNORE_UP + SNORE_DOWN kbd = Keyboard() cc = ConsumerControl() trellis = adafruit_trellism4.TrellisM4Express(rotation=ROTATION) for button in keymap: trellis.pixels[button] = keymap[button][0] current_press = set() last_press = time.monotonic() snore_count = -1 while True: pressed = set(trellis.pressed_keys) now = time.monotonic() sleep_time = now - last_press sleeping = sleep_time > TIMEOUT for down in pressed - current_press: if down in keymap and not sleeping: print("down", down) # Lower the brightness so that we don't draw too much current when we turn all of
def main(): trellis = adafruit_trellism4.TrellisM4Express() trellis.pixels.fill((0,0,0)) trellis.pixels.auto_write = False on_col = (0, 25, 0) alphabet = { 'A': 1959, # 4015, 'B': 4051, # 3922, 'C': 3993, 'D': 3990, 'E': 4057, # 4061, 'F': 4008, # 4010, 'G': 3995, 'H': 3951, 'I': 2553, 'J': 542, # 670, 'K': 3945, 'L': 3857, 'M': 3919, 'N': 3983, # 3975, 'O': 1686, 'P': 4004, 'Q': 1687, 'R': 4005, 'S': 1466, 'T': 2296, 'U': 3871, # 3615, 'V': 3614, 'W': 3887, 'X': 2891, 'Y': 3132, 'Z': 3033, # 2493, '0': 3999, '1': 1521, '2': 2485, '3': 2527, '4': 3631, '5': 3546, '6': 4027, # 1989, '7': 2191, # 2235, '8': 4031, '9': 3551, ' ': 0, '.': 16, ',': 288, '!': 208, '?': 180, ':': 144, ';': 2464, # 416, '\'': 192, '"': 200, # 196, '/': 300, '\\':3105, '<': 592, # 597, '>': 1312, # 1352, '+': 626, '-': 546, '*': 3264, # 1252, '^': 1156, '_': 273, '=': 1365, '(': 1680, ')': 2400, '[': 3984, ']': 2544, '{': 1273, '}': 2548, '#': 1782, # 1791, '%': 2349, '&': 1021, '|': 240, '$': 1266, '@': 1791, # 3831, '~': 612, '`': 2112, } def get_letter(c): c = c.upper() if c not in alphabet: return None b = alphabet[c] return set((2 - i // 4, 3 - i % 4) for i in range(12) if b & (1 << i)) def get_message(m): s = set() for i, c in enumerate(m): s ^= set((p[0] + 4 * i, p[1]) for p in get_letter(c)) return s btns = buttons.Buttons(trellis) pixels_on = get_message('hi') for p in pixels_on: trellis.pixels[p] = on_col fnames = [fname[:-3] for fname in os.listdir('.') if not fname.startswith('.') and fname.endswith('.py') and fname != 'code.py'] index = 0 length = len(fnames[index]) * 4 - 4 dots = get_message(fnames[index]) scroll = 0 while True: btns.update() p = (0, 0) for p in btns.pressed(): if (p[0] == 0 or p[0] == 7): if (p[0] == 0 and scroll - 2 >= 0): scroll -= 2 elif (p[0] == 7 and scroll + 2 <= length): scroll += 2 elif (p[1] == 0 or p[1] == 3): if (p[1] == 0 and index > 0): index -= 1 elif (p[1] == 3 and index < len(fnames)): index += 1 length = len(fnames[index]) * 4 - 4 dots = get_message(fnames[index]) scroll = 0 else: break if (0 < p[0] < 7 and 0 < p[1] < 3): break trellis.pixels.fill((0,0,0)) for dot in dots: if (0 <= dot[0] - scroll < 8 and 0 <= dot[1] < 4): trellis.pixels[dot[0] - scroll, dot[1]] = on_col trellis.pixels.show() time.sleep(0.05) deinit_trellis.deinit(trellis) mod = __import__(fnames[index]) print('import ' + mod.__name__) if 'main' in dir(mod): print(mod.__name__ + '.main') mod.main()