Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save 29liachen-pixel/a4e14490f6fb3ac3718c9a385486b856 to your computer and use it in GitHub Desktop.

Select an option

Save 29liachen-pixel/a4e14490f6fb3ac3718c9a385486b856 to your computer and use it in GitHub Desktop.
LC_Photoresistor
import time
import analogio
import board
import neopixel
photocell_pin = board.A2 #pin 0 is Analog input 2
photocell = analogio.AnalogIn(photocell_pin)
light = photocell.value
pixel_pin = board.D2
num_pixels = 16
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.5, auto_write=False)
WHITE=(255, 255, 255)
OFF=(0, 0, 0)
while True:
time.sleep(2.0)
print((photocell.value,))
if (photocell.value <= 15000): # this is the light threshold
pixels.fill(WHITE)
pixels.show()
else:
pixels.fill(OFF)
pixels.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment