# ♡ ∩_∩
# („• ֊ •„)♡
# | ̄U U ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
# | • Lenguajes de Interfaz en TECNM Campus ITT |
# | • Autor: Alejandro Suarez Sandoval |
# | • Fecha: 2025/05/21 |
# | • Descripción: Mostrando logo, texto y una animación con barra de progreso |
# | usando pantalla OLED SSD1306 y Raspberry Pi Pico. |
# | • Link simulación en Wokwi: https://wokwi.com/projects/431555956233679873 |
#  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
#
# ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂ ⠂⠄⠄⠂☆
# ═════════•°• Código en lenguaje MicroPython Raspberry Pi Pico•°•═══════
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf, sys
import utime
# Resolución de la pantalla OLED
pix_res_x = 128
pix_res_y = 64
# Función para inicializar la conexión I2C
def init_i2c(scl_pin, sda_pin):
i2c_dev = I2C(1, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=200000) # Se crea el bus I2C
i2c_addr = [hex(ii) for ii in i2c_dev.scan()] # Se escanean dispositivos conectados
if not i2c_addr:
print('No I2C Display Found') # Si no se detecta nada, se sale
sys.exit()
return i2c_dev
# Función para mostrar el logo de Raspberry Pi
def display_logo(oled):
# Logo en formato binario (32x32)
buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
oled.fill(0) # Limpia la pantalla
oled.blit(fb, 96, 0) # Dibuja el logo en la esquina superior derecha
oled.show() # Muestra el contenido en pantalla
# Función para mostrar texto inicial
def display_text(oled):
oled.text("Pepinisillo", 5, 5) # Línea de autor
oled.text("Barrita...", 5, 15) # Título de la animación
oled.show() # Mostrar en pantalla
# Función para mostrar una barra de progreso animada
def display_progress_bar(oled, total_time=15):
oled.text("Cargando:", 5, 30) # Texto que acompaña la barra
# Parámetros visuales de la barra
bar_width = 100
bar_height = 10
x_start = 5
y_start = 45
for t in range(total_time + 1):
# Limpia la zona de la barra
oled.fill_rect(x_start, y_start, bar_width, bar_height, 0)
# Calcula cuánto rellenar según el tiempo transcurrido
progress = int((t / total_time) * bar_width)
# Dibuja la barra de progreso y el borde
oled.fill_rect(x_start, y_start, progress, bar_height, 1)
oled.rect(x_start, y_start, bar_width, bar_height, 1)
oled.show()
utime.sleep(1) # Espera 1 segundo antes de actualizar
# Función principal
def main():
# Se inicializa la pantalla con pines 27 (SCL) y 26 (SDA)
i2c_dev = init_i2c(scl_pin=27, sda_pin=26)
oled = SSD1306_I2C(pix_res_x, pix_res_y, i2c_dev)
# Mostrar logo y texto con pausas
display_logo(oled)
utime.sleep(2)
display_text(oled)
utime.sleep(2)
# Limpia pantalla antes de mostrar animación
oled.fill(0)
oled.show()
# Inicia la barra de progreso animada
display_progress_bar(oled, total_time=15)
# Punto de entrada del script
if __name__ == '__main__':
main()