from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import utime
import random
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
led_verde = Pin(2, Pin.OUT)
led_azul = Pin(4, Pin.OUT)
led_naranja = Pin(5, Pin.OUT)
led_rojo = Pin(8, Pin.OUT)
def mostrar_en_oled(mensaje, numero):
oled.fill(0)
oled.text("" + mensaje, 0, 0)
oled.text("Nota: " + str(numero), 0, 20)
oled.show()
while True:
numero_aleatorio = random.randint(1, 20)
if numero_aleatorio > 12:
if numero_aleatorio % 2 == 0:
led_verde.on()
mostrar_en_oled("APROBADO", numero_aleatorio)
else:
led_azul.on()
mostrar_en_oled("APROBADO", numero_aleatorio)
else:
if numero_aleatorio % 2 == 0:
led_naranja.on()
mostrar_en_oled("DESAPROBADO", numero_aleatorio)
else:
led_rojo.on()
mostrar_en_oled("DESAPROBADO", numero_aleatorio)
print("Número generado:", numero_aleatorio)
utime.sleep(2)
led_verde.off()
led_azul.off()
led_naranja.off()
led_rojo.off()