Skip to content

Instantly share code, notes, and snippets.

@metachris
Last active June 3, 2016 10:09
Show Gist options
  • Save metachris/7ce03ece8193b3153aefee807a37cfad to your computer and use it in GitHub Desktop.
Save metachris/7ce03ece8193b3153aefee807a37cfad to your computer and use it in GitHub Desktop.
from gpiozero import Button, RGBLED
from signal import pause
button = Button(22, pull_up=True)
led = RGBLED(17, 18, 27)
colors = (
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(1, 0, 1),
(1, 1, 1)
)
color_now = 0
def btn_pressed(state=None):
global color_now
color = colors[color_now % len(colors)]
led.color = color
color_now += 1
print("btn pressed. new color:", color)
button.when_pressed = btn_pressed
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment