def draw_pattern(pattern): keypad.clear() for i in range(16): if i in pattern: button = pattern[i] keypad.illuminate(i, button[0], button[1], button[2]) keypad.update()
def scroll(): global PIXELS for j in range(1,4): for k in range(4): PIXELS[(4-j)*4+k] = max(0, PIXELS[(4-j-1)*4+k] - 75) keypad.illuminate((4-j)*4+k, 0, PIXELS[(4-j)*4+k] , 0) for i in range(4): if getrandbits(8) > 180: PIXELS[i] = random_color() keypad.illuminate(i, 0, PIXELS[i], 0) else: PIXELS[i] = 0 keypad.illuminate(i, 0, 0, 0) keypad.update()
def won(): on = 1 while True: # flash key 15 if on: keypad.illuminate(15, 0x00, 0x80, 0x00) on = 0 else: keypad.illuminate(15, 0x00, 0x00, 0x00) on = 1 keypad.update() time.sleep(1) # return when key 15 is pressed if keypad.get_button_states() == 32768: return
else: button = 0 for find in range(0, NUM_PADS): # check if this button is pressed and no other buttons are pressed if button_states & 0x01 > 0: if not (button_states & (~0x01)) > 0: lit = lit | (1 << button) break button_states >>= 1 button += 1 for i in range(0, NUM_PADS): if (lit >> i) & 0x01: if colour_index == 0: keypad.illuminate(i, 0x00, 0x20, 0x00) elif colour_index == 1: keypad.illuminate(i, 0x20, 0x20, 0x00) elif colour_index == 2: keypad.illuminate(i, 0x20, 0x00, 0x00) elif colour_index == 3: keypad.illuminate(i, 0x20, 0x00, 0x20) elif colour_index == 4: keypad.illuminate(i, 0x00, 0x00, 0x20) elif colour_index == 5: keypad.illuminate(i, 0x00, 0x20, 0x20) else: keypad.illuminate(i, 0x05, 0x05, 0x05) keypad.update() time.sleep(0.1)
def clear_display(): global PIXELS for pixel_index in range(16): PIXELS[pixel_index] = 0 keypad.illuminate(pixel_index, 0, 0, 0) keypad.update()