Elaborado por: Meza Rodriguez Eduardo Manuel Meza #21211997
Programa #1 "Texto estatico"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
# Inicializar I2C
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
# Mostrar texto
oled .fill (0 )
oled .text ("Hola, Pico W!" , 0 , 0 )
oled .text ("MicroPython" , 0 , 20 )
oled .text ("SSD1306 OLED" , 0 , 40 )
oled .show ()
`` `from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
# Inicializar I2C
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
# Mostrar texto
oled .fill (0 )
oled .text ("Hola, Pico W!" , 0 , 0 )
oled .text ("MicroPython" , 0 , 20 )
oled .text ("SSD1306 OLED" , 0 , 40 )
oled .show ()
Programa #2 "Contar segundos"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
start_time = utime .ticks_ms ()
while True :
elapsed = utime .ticks_diff (utime .ticks_ms (), start_time ) // 1000
oled .fill (0 )
oled .text ("Contador:" , 0 , 0 )
oled .text (str (elapsed ) + " seg" , 0 , 20 )
oled .show ()
utime .sleep (1 )
Programa #3 "Texto desplazante"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
text = "Pico W con OLED!"
x = 128
while True :
oled .fill (0 )
oled .text (text , x , 20 )
oled .show ()
x -= 2
if x < - len (text ) * 8 :
x = 128
utime .sleep_ms (50 )
Programa #4 "Formas geometricas"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
oled .fill (0 )
oled .rect (10 , 10 , 50 , 30 , 1 ) # Rectángulo (x, y, ancho, alto, color)
oled .fill_rect (70 , 10 , 20 , 20 , 1 ) # Rectángulo relleno
oled .ellipse (100 , 40 , 20 , 15 , 1 ) # Círculo (x, y, radio_x, radio_y, color)
oled .show ()
Programa #5 "Barra de progreso"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
width = 0
while True :
oled .fill (0 )
oled .text ("Progreso:" , 0 , 0 )
oled .rect (0 , 20 , 100 , 10 , 1 )
oled .fill_rect (0 , 20 , width , 10 , 1 )
oled .show ()
width = (width + 1 ) % 101
utime .sleep_ms (100 )
Programa #6 "Reloj digital"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
start_time = utime .ticks_ms ()
while True :
seconds = utime .ticks_diff (utime .ticks_ms (), start_time ) // 1000
mins = seconds // 60
secs = seconds % 60
oled .fill (0 )
oled .text ("Reloj Digital" , 0 , 0 )
oled .text (f"{ mins :02d} :{ secs :02d} " , 30 , 30 )
oled .show ()
utime .sleep (1 )
Programa #7 "Animacion puntos"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
x , y = 0 , 0
dx , dy = 2 , 2
while True :
oled .fill (0 )
oled .pixel (x , y , 1 )
oled .show ()
x += dx
y += dy
if x <= 0 or x >= 127 :
dx = - dx
if y <= 0 or y >= 63 :
dy = - dy
utime .sleep_ms (50 )
Programa #8 "Indicador de nivel"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
import math
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
t = 0
while True :
level = int (32 + 20 * math .sin (t / 10 ))
oled .fill (0 )
oled .text ("Nivel:" , 0 , 0 )
oled .fill_rect (0 , 64 - level , 20 , level , 1 )
oled .show ()
t += 1
utime .sleep_ms (100 )
Programa #9 "Logo Raspberry"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import framebuf
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
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 \x00 C\xe3 \x00 \x00 ~\xfc \x00 \x00 L'\x00 \x00 \x9c \x11 \x00 \x00 \xbf \xfd \x00 \x00 \xe1 \x87 \x00 \x01 \xc1 \x83 \x80 \x02 A\x82 @\x02 A\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 \x00 8\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 )
oled .blit (fb , 96 , 0 )
oled .text ("Raspberry Pi" , 0 , 40 )
oled .show ()
Programa #10 "Juego simple de pixel"
from machine import Pin , I2C
from ssd1306 import SSD1306_I2C
import utime
i2c = I2C (1 , scl = Pin (27 ), sda = Pin (26 ), freq = 400000 )
oled = SSD1306_I2C (128 , 64 , i2c )
# Configurar botones simulados (usar pines GPIO)
up = Pin (14 , Pin .IN , Pin .PULL_UP )
down = Pin (15 , Pin .IN , Pin .PULL_UP )
x , y = 64 , 32
while True :
oled .fill (0 )
oled .pixel (x , y , 1 )
oled .show ()
if up .value () == 0 :
y = max (0 , y - 1 )
if down .value () == 0 :
y = min (63 , y + 1 )
utime .sleep_ms (100 )