Skip to content

Instantly share code, notes, and snippets.

@BenjaminSantiago
Last active September 22, 2021 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminSantiago/d0136470aa93a81dce3c79e50bffffcc to your computer and use it in GitHub Desktop.
Save BenjaminSantiago/d0136470aa93a81dce3c79e50bffffcc to your computer and use it in GitHub Desktop.
make it so button A lights up half the neopixels button B lights up the other half and pressing A & B lights up both halves
"""
make it so button A lights up half the neopixels
button B lights up the other half
and pressing A & B lights up both halves
"""
# our imports
# -------------------------------------------
from adafruit_circuitplayground import cp
# -------------------------------------------
# main loop
# -------------------------------------------
while True:
# if we are pressing only button a
# (not button b)
# turn on pixels 1 - 5
# turn off the rest
if cp.button_a and not cp.button_b:
for p in range(0,5):
cp.pixels[p] = (255, 0, 0)
for p in range(5, 10):
cp.pixels[p] = (0, 0, 0)
# if we are pressing only button b
# (not button a)
# turn on pixels 6 - 10
# turn off the rest
elif cp.button_b and not cp.button_a:
for p in range(5, 10):
cp.pixels[p] = (0, 0, 255)
for p in range(0, 5):
cp.pixels[p] = (0, 0, 0)
# if we press both, turn on all of 'em
elif cp.button_a and cp.button_b:
cp.pixels.fill((255, 0, 255))
# otherwise, everything off
else:
cp.pixels.fill((0, 0, 0))
# -------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment