# Ex 1 - Par Ímpar -------------------------------------------------------
# num = int(input("Digite um número: "))
# if num % 2 == 0:
# print(f"O número {num} é par.")
# else:
# print(f"O número {num} é ímpar.")
# Ex 2 - Calculadora -----------------------------------------------------
# while True:
# num1 = int(input("Número 1:\n> "))
# num2 = int(input("Número 2:\n>"))
# operacao = int(input("Operacao:\n1 - Soma\n2 - Subtração\n3 - Multiplicação\n4 - Divisão\n> "))
# if operacao == 1:
# print(num1 + num2)
# elif operacao == 2:
# print(num1 - num2)
# elif operacao == 3:
# print(num1 * num2)
# elif operacao == 4:
# print(num1 / num2)
# else :
# print("Opção inválida!")
# opcao = input("Deseja encerrar o programa? (s/n) ")
# if opcao.lower() == "s":
# break
# Ex 3 - Contagem regressiva ---------------------------------------------
# import time
# for i in range(10, 0, -1):
# print(i)
# time.sleep(1)
# print("Fim da contagem!")
# Ex 4 - Estado de um botão ----------------------------------------------
# import machine
# import time
# botao = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
# msg = ""
# msgAnterior = ""
# while True:
# if botao.value() == 0:
# msg = "Pressionado"
# else:
# msg = "Não pressionado"
# if msg != msgAnterior:
# print(msg)
# msgAnterior = msg
# time.sleep_ms(50)
# Ex 5 - Botão com led ---------------------------------------------------
# import machine
# import time
# led1 = machine.Pin(13, machine.Pin.OUT)
# botao1 = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
# led2 = machine.Pin(14, machine.Pin.OUT)
# botao2 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP)
# while True:
# if botao1.value() == 0:
# led1.on()
# else:
# led1.off()
# if botao2.value() == 0:
# led2.on()
# else:
# led2.off()
# time.sleep_ms(50)
# Ex 6 - Semáforo ---------------------------------------------------------
# import machine
# import time
# vermelho = machine.Pin(26, machine.Pin.OUT)
# amarelo = machine.Pin(14, machine.Pin.OUT)
# verde = machine.Pin(13, machine.Pin.OUT)
# while True:
# vermelho.on()
# time.sleep(5)
# vermelho.off()
# verde.on()
# time.sleep(5)
# verde.off()
# amarelo.on()
# time.sleep(2)
# amarelo.off()
# Ex 7 - Potenciômetro ---------------------------------------------------
# import machine
# import time
# potenciometro = machine.ADC(machine.Pin(26))
# potenciometro.atten(machine.ADC.ATTN_11DB)
# while True:
# valor = potenciometro.read()
# print("Valor do potenciômetro: {}".format(valor))
# time.sleep(1)
# Ex 8 - Temperatura com visor
import ssd1306
import machine
import dht
import time
i2c = machine.I2C(scl=machine.Pin(32), sda=machine.Pin(33))
display = ssd1306.SSD1306_I2C(128, 64, i2c)
sensor = dht.DHT22(machine.Pin(21))
while True:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
display.fill(0)
display.text('Temp: {:.1f} C'.format(temp), 0, 0)
display.text('Hum: {:.1f} %'.format(hum), 0, 20)
display.show()
time.sleep(5)