from machine import Pin, I2C
from utime import sleep
from hcsr04 import HCSR04
from ssd1306 import SSD1306_I2C
s1=Pin(13,Pin.IN,Pin.PULL_DOWN)#ROJO
ancho= 128
alto=64
i2c = I2C(0, scl=Pin(25), sda=Pin(26))
oled= SSD1306_I2C(ancho, alto, i2c)
oled.write_cmd(0x0)
oled.write_cmd(0x0)
oled.fill(s1.value())
oled.text("Distancia",28,28,not (s1.value))
oled.show()
hc04 = HCSR04(trigger_pin=12, echo_pin=14)
while True:
sleep(0.1)
distancia = hc04.distance_cm()
oled.fill(1)
oled.text("Distancia",28,16,0)
oled.text(f"{distancia:0.2f}cm", 28, 28 ,0)
oled.show()
print("Distancia = {:02.2f} cm".format(distancia))