#Importamos las librerias necesarias -
from machine import Pin, I2C, ADC
import time
import ssd1306
import framebuf
#Importamos las librerias necesarias -
#Definimos el dispositivo i2c conectado
i2c = I2C(-1,scl=Pin(22), sda=Pin(21))
#Establecemos los parametros del display a utilizar (horizontal,vertical,puerto)
display = ssd1306.SSD1306_I2C(128, 64, i2c)
#Logo creado con el codigo anexado en la carpeta 'code'
buffer = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xc0\x80\x00\x00\x00\x00\x00\x00\x00\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf0\xf8\xfe\xfe\xfc\xf8\xf0\xe0\xe0\xc0\x80\x00\x00\x00\x00\x00\xe0\xe0\xc0\xc4\x8c\x1c<|\xfc\xfc\xf8\xf8\xf8\xf8\xf8\xf8\xf0\xf0\xf0\xe0\xc0\x00\x00p\xf0\xf0\xe0\xe0\xe0\xc0\xc0\xc0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e?\xff\xff\xff\xff\xff\xfe\xfc\xf8\xf8\xfc\xfc\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\xff\xff\xff\xff\x7f?\x1f\x0f\x0f\x07\x02\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x01\x03\x0f\x1f?\xff\xff\xff\xff\xff\xff\xff\x00\x00\xf0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xfe\xfc\xf8\xf0\xe0@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x80\x80\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000x\xfe\xff\xff\xfe\xfe\xfe\xfc\xfc\xfe\xff?\x9f\xcf\xe7s3\x99\x9d\x8c\x8e\x86\x86\x86\x86\x87\x07\x07\x86\x86\x86\x86\x8c\x8c\x9c\xb8\xf0c\xe1\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07?\xff\xff\xff\xff\xc1\x00\x00\x00\x00\x00\x00\x00\x01\x07\x0f?\x7f\x0f\xe0\xfc\xff\xff\xff\xff\x7f\x7f???\x9f\x9f\x8f\xc7\xc7\xe3\xe1\xf1\xf0\xf8\xfc\xfe\xfe\x0f\x04\x04\x06\x06\x02\x02\x83\x83\x83\x83\x83\xe3\xff\x7f?\x0f\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xc0\xc0\xc0\xc0\xe0\xf9\xff\xff\xff\xff\x0f\xc3\xf8~\x0f\x03\x00\x00\x00\xff\xff\xff\xff\x80\x80\xff\xff\xff\xff\x00\xff\xff\xff\xff\x98\xf9\xfb\xfb\xfb\x00\x01\x03\x0f\xfe\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x0f\x1f?\xf0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x8d\x9d}||\xfe\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\xc0\xc0`00\x1f\x1f\x1f\x1f\x0f\x0f\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x1f\x1f\x1f\x1f???\xff\xff\xff\xff\xff\x80\x1f\xff\xf0\x00\x00\x00\x00\x00\x01\xf1\xf5\xf5\xf55555\x04\xfc\xfc\xfd\r\xe5\xf5\xf5\xe1\x01\x00\x00\x00\x00\x80\xff\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x80\xc0\xe0p8\x1c\x0c\x06\x03\x01\x00\x00\x00\x00\x06\x1c\xbd\xf9\xfb\xf3\xf7\xe7\xe7\xff\xff\xdf\xdf\x8f\x9f\x9f\x9f\x9f\x1f\x1f\x1f\x18\x10\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\x7f\x07\x00\x00\x00\x00\x00\x00\x00\x00`\xf0\xf0\xf8\xfd\xff\xff\xff\xff\xff\xfc\xf0\xe3\xcf\x9c8p\xe0\xc0\x8f\x9f\x1f\x1f\x19\x19\x18\x08\x00\x0f\x1f\x1f\x00\x0f\x0f\x8f\x8f\xc0\xe0p8\x1e\x0f\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x0f\x0f\x0f\x0e\x0c\x0c\x0c\x0c\x0c\x06\x06\x06\x06\x03\x03\x01\x01\x01\x00\x01\x03\x03\x07\x0f\x1f\x1f??\x7f\x7f\x7f\x7f???\x9f\xdf\xcf\xef\xe7\xf3\xf3\xf9\xf8\xfc\xfe\xfe\xff\xff\xff\x7f\x1f\x0f\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x07\x07\x07\x07\x03\x03\x01\x03\x87\xef\xff\xff\xff\xff\xfe\xfc\xfd\xf9\xfb\xf3\xf3\xf7\xf6\xf6\xf6\x06\x06\x06\x06\x07\x03\x03\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xe0\xe0````````\x00\xc0\xe0\xe0````````\x00\xc0\xe0\xe0````````\x00\x80\x80\x00\x00\x00\x00\x80\x80\x00`````\xe1\xe1\xe1ccccc\xc3\xe3\xe3a```````\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x07\x0f\x0f\x1f\x1f\x0f\x07\x01\x00\x01\x01\x01\x1f\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f??00000000\x00\x1f??77777777\x02\x1f??00000000\x00\x01\x03\x07>>\x07\x03\x01\x00\x00\x00\x00\x00\x00???\x00\x00\x00\x00\x00\x1f??77777777\x00\x00\x00')
fb = framebuf.FrameBuffer(buffer, 128, 64, framebuf.MVLSB)
display.fill(0)
display.framebuf.blit(fb, 0, 0)
display.show()
time.sleep(2.5)
#Definimos el pin del sensor y la configuracion del pin ADC en entrada de datos
sensor = ADC(Pin(34))
sensor.atten(ADC.ATTN_11DB)
while True:
sens_value = sensor.read()
val = sens_value*10
disval = str(val)
if val < 1000:
display.fill(0)
display.text('inspiracion', 10, 10)
display.text(disval, 10, 30)
display.show()
if val > 1600:
display.fill(0)
display.text('espiracion', 10, 10)
display.text(disval, 10, 30)
display.show()
else:
display.fill(0)
display.text(disval, 10, 30)
display.show()
time.sleep(0.1)