Created
May 6, 2026 18:11
-
-
Save 29liachen-pixel/a4e14490f6fb3ac3718c9a385486b856 to your computer and use it in GitHub Desktop.
LC_Photoresistor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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