/ Proximity_Light / code.py
code.py
 1  # SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import board
 7  import busio
 8  import neopixel
 9  import adafruit_vl53l0x
10  
11  TRIGGER_DISTANCE = 500          # number of mm where the light toggles
12  NEOPIXEL_PIN = board.D1
13  NUMBER_OF_PIXELS = 8
14  
15  i2c = busio.I2C(board.SCL, board.SDA)
16  sensor = adafruit_vl53l0x.VL53L0X(i2c)
17  
18  strip = neopixel.NeoPixel(NEOPIXEL_PIN, NUMBER_OF_PIXELS, brightness=1.0, auto_write=False)
19  
20  strip.fill((0, 0, 0))
21  for i in range(NUMBER_OF_PIXELS):
22      strip[i] = (64, 64, 64)
23      strip.show()
24      time.sleep(0.1)
25      strip[i] = (0, 0, 0)
26      strip.show()
27  
28  while True:
29      if sensor.range < TRIGGER_DISTANCE:
30          strip.fill((255, 255, 255))
31          strip.show()
32      else:
33          strip.fill((0, 0, 0))
34          strip.show()
35      time.sleep(0.1)