Added 6-te December

This commit is contained in:
Joachim Hummel 2023-12-06 21:28:00 +00:00
parent d33ef55963
commit 9b2b6d37ac
1 changed files with 44 additions and 0 deletions

44
6-dezember.py Normal file
View File

@ -0,0 +1,44 @@
# Imports
from machine import ADC, Pin
import time
# Set up the LED pins
red = Pin(18, Pin.OUT)
amber = Pin(19, Pin.OUT)
green = Pin(20, Pin.OUT)
# Define pin for our sensor
lightsensor = ADC(Pin(26))
while True: # Run forever
# Read sensor value and store it in a variable called 'light'
light = lightsensor.read_u16()
# Use the round function to limit the decimal places to 1
lightpercent = round(light/65535*100,1)
# Print our reading percentage with % symbol
print(str(lightpercent) +"%")
# 1 second delay between readings
time.sleep(1)
if lightpercent <= 30: # If percentage is less than or equal to 30
red.value(1) # Red LED on
amber.value(0)
green.value(0)
elif 30 < lightpercent < 60: # If percentage is between 30 and 60
red.value(0)
amber.value(1) # Amber LED on
green.value(0)
elif lightpercent >= 60: # If percentage is greater than or equal to 60
red.value(0)
amber.value(0)
green.value(1) # Green LED on