/ examples / circuitplayground_buttons_neopixels.py
circuitplayground_buttons_neopixels.py
 1  """This example lights up half the NeoPixels red while button A is being pressed, and half the
 2  NeoPixels green while button B is being pressed."""
 3  from adafruit_circuitplayground.express import cpx
 4  
 5  cpx.pixels.brightness = 0.3
 6  cpx.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!
 7  
 8  while True:
 9      if cpx.button_a:
10          cpx.pixels[0:5] = [(255, 0, 0)] * 5
11      else:
12          cpx.pixels[0:5] = [(0, 0, 0)] * 5
13  
14      if cpx.button_b:
15          cpx.pixels[5:10] = [(0, 255, 0)] * 5
16      else:
17          cpx.pixels[5:10] = [(0, 0, 0)] * 5