Skip to content

Instantly share code, notes, and snippets.

@PaulKinlan
Last active February 22, 2021 10:15
Show Gist options
  • Save PaulKinlan/9b9d80492c090d025539cbc943235d87 to your computer and use it in GitHub Desktop.
Save PaulKinlan/9b9d80492c090d025539cbc943235d87 to your computer and use it in GitHub Desktop.
pico_rgb_game.py
import picokeypad as keypad
import random
import time
debug = 0
keypad.init()
keypad.set_brightness(1.0)
guess = random.randint(0, 15)
guess_bit_mask = 1 << guess
# keypad.clear()
for button in range(0, 16):
keypad.illuminate(button, 0x0, 0x0, 0x0)
while True:
button_states = keypad.get_button_states()
if debug > 0:
keypad.illuminate(guess, 0, 0, 0xff)
print(button_states & guess_bit_mask)
if button_states > 0:
if button_states == 0b1001:
for button in range(0, 16):
keypad.illuminate(button, 0x0, 0x0, 0x0)
guess = random.randint(0, 15)
guess_bit_mask = 1 << guess
continue
if button_states & guess_bit_mask > 0:
keypad.illuminate(guess, 0x0, 0xff, 0x0)
else:
for pressed_button in range(0, 16):
if 1 << pressed_button & button_states:
keypad.illuminate(pressed_button, 0xff, 0x0, 0x0)
keypad.update()
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment