Skip to content

Instantly share code, notes, and snippets.

@bennuttall bennuttall/dots.py
Last active Dec 16, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.