code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  Circuit Playground Bluefruit NeoPixel Light Meter.
 7  
 8  Shine a light on the front of the Circuit Playground Bluefruit to see the number of NeoPixels lit
 9  up increase. Cover the front of the CPB to see the number decrease.
10  """
11  from adafruit_circuitplayground import cp
12  
13  # Choose a color. Defaults to cyan. This is an RGB value, where (r, g, b) represents red, green,
14  # and blue. Each value has a range of 0-255, where 0 is off and 255 is max intensity. You can
15  # update these values to change the colors. For example, (0, 255, 0) would be max green. You can
16  # combine numbers within the range to make other colors such as (255, 0, 180) being pink.
17  # Try it out!
18  color_value = (0, 255, 255)
19  
20  cp.pixels.auto_write = False
21  cp.pixels.brightness = 0.3
22  
23  
24  def scale_range(value):
25      """Scale a value from 0-320 (light range) to 0-9 (NeoPixel range).
26      Allows remapping light value to pixel position."""
27      return round(value / 320 * 9)
28  
29  
30  while True:
31      peak = scale_range(cp.light)
32  
33      for i in range(10):
34          if i <= peak:
35              cp.pixels[i] = color_value
36          else:
37              cp.pixels[i] = (0, 0, 0)
38      cp.pixels.show()