import machine
import utime as time
#### SENSOR 2 - MELTDOWN SENSOR
# Configure GP17 as output and define it as melt_led_pin
melt_led_pin = machine.Pin(17, machine.Pin.OUT)
melt_led_status = "Off" # Define a variable called melt_led_status and set it to "Off"
# Define a function to get the red LED status
def get_melt_led_status():
return "On" if melt_led_pin.value() == 1 else "Off"
# Function to periodically check the ADC value and control the redLED
def check_adc_and_control_melt_led():
global melt_led_status # Declare melt_led_status as global
adc = machine.ADC(14)
while True:
temperature = adc.read_u16() * 3.3 / 65535 # Convert ADC reading to voltage
temperature = (temperature - 0.5) * 100 # Convert voltage to temperature in Celsius
print("Temperature:", temperature)
if temperature > 40: # ADJUST VALUE BASED ON NEEDS
print("Temperature too high, turning on the red LED")
melt_led_pin.on()
else:
print("Temperature okay, turning off the red LED")
melt_led_pin.off()
melt_led_status = get_melt_led_status() # Update melt_led_status
print("MELT LED STATUS:", melt_led_status)
time.sleep(0.1)
#### SENSOR 1 - ENVIRONMENT SENSOR
# Configure GP18 as output and define it as env_led_pin
env_led_pin = machine.Pin(18, machine.Pin.OUT)
env_led_status = "Off" # Define a variable called env_led_status and set it to "Off"
# Define a function to get the red LED status
def get_env_led_status():
return "On" if env_led_pin.value() == 1 else "Off"
# Function to periodically check the ADC value and control the redLED
def check_adc_and_control_env_led():
global env_led_status # Declare env_led_status as global
adc = machine.ADC(15)
while True:
temperature = adc.read_u16() * 3.3 / 65535 # Convert ADC reading to voltage
temperature = (temperature - 0.5) * 100 # Convert voltage to temperature in Celsius
print("Temperature:", temperature)
env_led_status = get_env_led_status() # Update env_led_status
print("ENVIRONMENT LED STATUS:", env_led_status)
time.sleep(0.1)
# Turn Light off if meltdown occurs
while True:
if get_melt_led_status() == "On":
env_led_pin.off()
#### SENSOR - PHOTORESISTOR
# Setting up all pins
photo_led_pin = machine.Pin(16, machine.Pin.OUT)
photoresistor_pin = machine.Pin(19, machine.Pin.IN)
while True:
# Read the value from the photoresistor
photoresistor_value = photoresistor_pin.value()
# If the photoresistor detects it has been covered that represents the hood being closed (dark)
if photoresistor_value == 1:
# Turn on the LED
photo_led_pin.on()
print("Covered")
else:
# Turn off the LED
photo_led_pin.off()
print("Not Covered")
# Delay for stability
time.sleep(0.1)