Last active
August 27, 2023 00:05
-
-
Save bennuttall/c123175d7475092de4b9 to your computer and use it in GitHub Desktop.
DOTS Python code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import InputDevice | |
NUM_PINS = 28 | |
PULL_UP_PINS = [2, 3] | |
PINS = list(set(list(range(NUM_PINS))) - set(PULL_UP_PINS)) | |
MINIMUM_DOTS_REQUIRED = 5 | |
COLOR_PINS = { | |
27: 'red', | |
10: 'green', | |
0: 'blue', | |
19: 'orange', | |
} | |
DOT_PINS = list(set(PINS) - set(COLOR_PINS.keys())) | |
def inspect_dot(pin): | |
dot = InputDevice(pin, pull_up=True) | |
return dot.is_active | |
def get_selected_dots(pins=DOT_PINS): | |
return [pin for pin in pins if inspect_dot(pin)] | |
def get_selected_colors(): | |
color_dots = get_selected_dots(COLOR_PINS.keys()) | |
return [COLOR_PINS[pin] for pin in color_dots] | |
def enough_dots_connected(): | |
selected_dots = get_selected_dots() | |
active_dots = len(selected_dots) | |
return active_dots >= MINIMUM_DOTS_REQUIRED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment