Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active August 27, 2023 00:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennuttall/c123175d7475092de4b9 to your computer and use it in GitHub Desktop.
Save bennuttall/c123175d7475092de4b9 to your computer and use it in GitHub Desktop.
DOTS Python code
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