from machine import Pin, I2C, ADC
from ssd1306 import SSD1306_I2C
import utime
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
valor_analogo = ADC(26)
boton = Pin(14, Pin.IN, Pin.PULL_DOWN)
red = Pin(16, Pin.OUT)
green = Pin(18, Pin.OUT)
blue = Pin(20, Pin.OUT)
factor_conversion = 3.3 / 65535
while True:
lectura = valor_analogo.read_u16()
voltaje = round(lectura * factor_conversion, 2)
oled = SSD1306_I2C(128, 64, i2c)
oled.text("Voltaje: " + str(voltaje) + "V", 0, 0)
if voltaje > 2.0 and boton.value() == 1:
red.value(1)
green.value(0)
blue.value(0)
oled.text("ALTO + BOTON", 0, 25)
elif voltaje >= 1.0 and voltaje <= 2.0:
red.value(0)
green.value(0)
blue.value(1)
oled.text("NIVEL MEDIO", 0, 25)
else:
red.value(0)
green.value(1)
blue.value(0)
oled.text("NIVEL BAJO", 0, 25)
oled.show()
utime.sleep(0.3)Loading
ssd1306
ssd1306