Advertisement
belrey10

Day 5: Approach to the Inmost Cave – Integrating a Photoresistor

Nov 4th, 2024 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. from machine import Pin, ADC
  2. import time
  3.  
  4. # Initialize the LED and photoresistor
  5. led = Pin(15, Pin.OUT)
  6. photoresistor = ADC(Pin(26))
  7.  
  8. while True:
  9.   # Read the value from the photoresistor
  10.   light_level = photoresistor.read_u16()
  11.  
  12.   # Print the light level (optional for debugging)
  13.   print(light_level)
  14.  
  15.   # Control the LED based on the light level
  16.   if light_level < 20000:
  17.     led.on()
  18.   else:
  19.     led.off()
  20.  
  21.   # Delay for a short period
  22.   time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement