Toggle Navigation
Hatchery
Eggs
Horizontal and vertical scrollers
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import keypad, display, time R = 0xFF0000 G = 0x00FF00 B = 0x0000FF W = 0xFFFFFF O = 0xFFA500 Y = 0xFFFF00 def horizontal_scroll(background, pattern): display.drawFill(background) display.flush() cols = len(pattern[0]) for t in range(cols+4): if t < cols: for i in range(4): display.drawPixel(3, i, pattern[i][t]) else: for i in range(4): display.drawPixel(3, i, background) if t > 0 and t < cols+1: for i in range(4): display.drawPixel(2, i, pattern[i][t-1]) else: for i in range(4): display.drawPixel(2, i, background) if t > 1 and t < cols+2: for i in range(4): display.drawPixel(1, i, pattern[i][t-2]) else: for i in range(4): display.drawPixel(1, i, background) if t > 2 and t < cols+3: for i in range(4): display.drawPixel(0, i, pattern[i][t-3]) else: for i in range(4): display.drawPixel(0, i, background) display.flush() time.sleep(1) def vertical_scroll(background, pattern): display.drawFill(background) display.flush() rows = len(pattern) for t in range(rows+4): if t < rows: for i in range(4): display.drawPixel(i, 3, pattern[t][i]) else: for i in range(4): display.drawPixel(i, 3, background) if t > 0 and t < rows+1: for i in range(4): display.drawPixel(i, 2, pattern[t-1][i]) else: for i in range(4): display.drawPixel(i, 2, background) if t > 1 and t < rows+2: for i in range(4): display.drawPixel(i, 1, pattern[t-2][i]) else: for i in range(4): display.drawPixel(i, 1, background) if t > 2 and t < rows+3: for i in range(4): display.drawPixel(i, 0, pattern[t-3][i]) else: for i in range(4): display.drawPixel(i, 0, background) display.flush() time.sleep(1) def on_key(key_index, pressed): x, y = key_index % 4, int(key_index / 4) if pressed: pat = patterns.get(key_index, default) print("Selected pattern {}".format(key_index)) if pat == default: default() else: pat[0](pat[1], pat[2]) def default(): display.drawFill(W) display.flush() display.drawFill(W) display.flush() patterns = { # Heart 0:[horizontal_scroll, W, [[W,R,W,R,W], [R,R,R,R,R], [W,R,R,R,W], [W,W,R,W,W]]], # Vertical arrow sliding horizontally 1:[horizontal_scroll, W, [[W,W,O,W,W], [W,O,O,O,W], [O,O,O,O,O], [W,W,O,W,W]]], # YMCA 2:[horizontal_scroll, W, [[Y,W,Y,W,G,W,W,W,G,W,R,R,R,W,W,B,W], [Y,W,Y,W,G,G,W,G,G,W,R,W,W,W,B,W,B], [W,Y,W,W,G,W,G,W,G,W,R,W,W,W,B,B,B], [W,Y,W,W,G,W,W,W,G,W,R,R,R,W,B,W,B]]], # Vertical arrow sliding vertically 3:[vertical_scroll, W, [[W,R,W,W], [R,R,R,W], [W,R,W,W], [W,R,W,W], [W,R,W,W]]] } keypad.add_handler(on_key)