"""
MicroPython code for ESP32
Usage:
1. Go to ...
2.
"""
# DEFINIZIONI, DICHIARAZIONI E VARIABILI GLOBALI
from machine import Pin
from time import sleep
import dht
# DEFINIZIONI, DICHIARAZIONI E VARIABILI HARDWARE (HW)
led = Pin(21,Pin.OUT)
button = Pin( 2,Pin.IN)
sensor = dht.DHT22(Pin(12))
temp = -999
hum = -999
# ALGORITMO ITERATIVO
print("Measuring Weather conditions with DHTxx sensor... ", end="")
while True:
# Fa misurazione ambientali
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print(f"Temperatura: {temp}, Umidità: {hum}")
# Verifica la presenza di un comando
print(f"PRINT : Pulsante = {button.value()}")
if button.value():
print(f"PRINT : Pulsante = {button.value()}")
for i in range(10):
led.value(True)
sleep(.5)
led.value(False)
sleep(.5)
sleep(1)