# Base del programa
# Programmer: Adrian Josele G. Quional
# Display Image & text on I2C driven ssd1306 OLED display
# retoque por Juan Tonda
#from PIL import Image
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
import machine
import utime
running = False
texto="ON"
contador=0
# definir interrupción para ver estado
def interrupcion(pin):
global running
running = not running
#contador=contador+1
#Habilitar PIN-5 (botón)
GP5 = machine.Pin(5, machine.Pin.OUT)
WIDTH = 128 # oled display width
HEIGHT = 64 # oled display height
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=200000) # Init I2C using pins GP8 & GP9 (default I2C0 pins)
print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c)) # Display I2C config
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init oled display
# Raspberry Pi logo as 32x32 bytearray
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")
while True:
if running:
texto="ON-----"
contador=0
else:
texto="OFF----"
contador=contador+1
# Carga el buffer del logotipo Raspbery
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
# Limpiar pantalla
# -- oled.fill(0)
# Muestra la imagen
# oled.fill(0)
# oled.fill_rect(0, 0, 32, 32, 1)
# oled.fill_rect(2, 2, 28, 28, 0)
# oled.vline(9, 8, 22, 1)
# oled.vline(16, 2, 22, 1)
# oled.vline(23, 8, 22, 1)
# oled.fill_rect(26, 24, 2, 4, 1)
# oled.text('MicroPython', 40, 0, 1)
# oled.text('SSD1306', 40, 12, 1)
# oled.text('OLED 128x64', 40, 24, 1)
# utime.sleep(2)
oled.fill(0)
# oled.text("Pulsar",40, 0, 1)
# oled.text("botón",40, 12, 1)
# Add some text
#oled.text("ADC: ",5,8)
#oled.text("hola",15,9)
oled.blit(fb, 96, 0)
oled.text(texto,17,9)
oled.text(str(contador),19,1)
# Muestra el resultado en pantalla
oled.show()
# control para la interrupción, cuando se pulsa el botón
boton=machine.Pin(5, machine.Pin.IN, machine.Pin.PULL_UP)
boton.irq(interrupcion, machine.Pin.IRQ_RISING)