import machine
import utime as time
#### SENSOR 2 - MELTDOWN SENSOR
# Configure GP17 as output and define it as redLED_pin
redLED_pin = machine.Pin(17, machine.Pin.OUT)
redLED_status = "Off" # Define a variable called redLED_status and set it to "Off"
# Define a function to get the red LED status
def get_redLED_status():
return "On" if redLED_pin.value() == 1 else "Off"
# Function to periodically check the ADC value and control the redLED
def check_adc_and_control_redLED():
global redLED_status # Declare redLED_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")
redLED_pin.on()
else:
print("Temperature okay, turning off the red LED")
redLED_pin.off()
redLED_status = get_redLED_status() # Update redLED_status
print("Red LED Status:", redLED_status)
time.sleep(1)
####
# Setting up all pins
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, representing the hood being closed (dark)
if photoresistor_value == 1:
# Turn on the LED
led_pin.on()
print("Covered")
else:
# Turn off the LED
led_pin.off()
print("Not Covered")
# Delay for stability
time.sleep(0.1)
Loading
pi-pico-w
pi-pico-w