code.py
 1  # SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import board
 7  from analogio import AnalogIn
 8  import neopixel
 9  
10  NUMPIXELS = 10  # Circuit Playground Express has 10 pixels
11  pixels = neopixel.NeoPixel(board.NEOPIXEL, NUMPIXELS, auto_write=False)  # CPX NeoPixels
12  potentiometer = AnalogIn(board.A1)  # potentiometer connected to A1, power & ground
13  
14  def show_value(val):            # Show value 0-9 on CPX NeoPixels
15      for i in range(val):
16          pixels[i] = (50, 0, 0)  # Red
17      for i in range(val, NUMPIXELS):
18          pixels[i] = (0, 0, 0)
19      pixels.show()
20  
21  while True:
22  
23      show_value(int(potentiometer.value / 65520 * NUMPIXELS))  # Show on NeoPixels
24      print((potentiometer.value,))                             # Print value
25  
26      time.sleep(0.25)                   # Wait a bit before checking all again