/ examples / circuitplayground_light_neopixels.py
circuitplayground_light_neopixels.py
 1  """THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
 2  This example requires the simpleio.mpy library.
 3  
 4  This example uses the light sensor on the CPX, located net to the picture of the eye on the board.
 5  Once you have the library loaded, try shining a flashlight on your CPX to watch the number of
 6  NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease."""
 7  import time
 8  from adafruit_circuitplayground.express import cpx
 9  import simpleio
10  
11  cpx.pixels.auto_write = False
12  cpx.pixels.brightness = 0.3
13  
14  while True:
15      # light value remapped to pixel position
16      peak = simpleio.map_range(cpx.light, 0, 320, 0, 10)
17      print(cpx.light)
18      print(int(peak))
19  
20      for i in range(0, 10, 1):
21          if i <= peak:
22              cpx.pixels[i] = (0, 255, 255)
23          else:
24              cpx.pixels[i] = (0, 0, 0)
25      cpx.pixels.show()
26      time.sleep(0.05)