Forked from Jivemofo/gist:4d6525387b91a2e93755b353a9f1cf7a
Last active
June 26, 2019 20:17
-
-
Save seantibor/608186579b2683265d56aa457f7c4b91 to your computer and use it in GitHub Desktop.
Circuit Playground Express Led Button Test
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
# this program detects a button press and lights up a new Led, 2nd button changes colors | |
from adafruit_circuitplayground.express import cpx, time | |
cpx.pixels.brightness = 0.3 | |
cpx.pixels.fill((0, 0, 0)) | |
# pick how many colors to use | |
color_mode = 3 | |
RED = (255, 0, 0) | |
GREEN = (0, 255, 0) | |
BLUE = (0, 0, 255) | |
def color_switcher(new_color): | |
switcher = { | |
1: RED, | |
2: GREEN, | |
3: BLUE, | |
} | |
# get the color from switcher dictionary with black as default | |
return switcher.get(new_color, (0,0,0)) | |
counter = 0 | |
current_color = 0 | |
while True: | |
# check the buttons | |
if cpx.button_a: | |
# add 1 to counter | |
counter += 1 | |
# use mod to set counter range 0 to 9 | |
counter %= 9 | |
print("Button A pressed!") | |
time.sleep(1) | |
elif cpx.button_b: | |
current_color %= 3 | |
current_color += 1 | |
print("Button B pressed!") | |
time.sleep(1) | |
# output to LED's | |
else: | |
print("Current counter = {}".format(counter)) | |
print("Current Color = {}".format(current_color)) | |
time.sleep(.5) | |
cpx.pixels.fill = (color_switcher(current_color)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment