code.py
1 # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 NeoPixel brightness proximity example. Increases the brightness of the NeoPixels as you move closer 7 to the proximity sensor. 8 """ 9 import time 10 import board 11 import neopixel 12 from adafruit_apds9960.apds9960 import APDS9960 13 14 apds = APDS9960(board.I2C()) 15 pixels = neopixel.NeoPixel(board.NEOPIXEL, 2) 16 17 apds.enable_proximity = True 18 19 20 def proximity_to_brightness(value): 21 """Maps the proximity values (0 - 255) to the brightness values (0.0 - 1.0)""" 22 return value / 255 * 1.0 23 24 25 pixels.fill((255, 0, 0)) 26 27 while True: 28 print(apds.proximity) 29 pixels.brightness = proximity_to_brightness(apds.proximity) 30 time.sleep(0.2)