from machine import Pin, I2C
import ssd1306
from time import sleep
import math
# Configuración de los pines para los interruptores
switch_func = Pin(19, Pin.IN, Pin.PULL_UP) # Interruptor para cambiar entre senoidal e inversa
switch_freeze = Pin(18, Pin.IN, Pin.PULL_UP) # Interruptor para congelar la muestra de datos
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
seno_normal = True # Flag para controlar si se muestra la función senoidal normal o inversa
freeze_display = False # Flag para congelar la muestra de datos
while True:
for anguloGrados in range(0, 360, 5):
anguloRadianes = (math.pi * anguloGrados) / 180
xLinea = int(math.cos(anguloRadianes) * 24)
yLinea = int(math.sin(anguloRadianes) * 24)
for anguloGrados in range(0, 360, 5):
anguloRadianes = (math.pi * anguloGrados) / 180
x = int(math.cos(anguloRadianes) * 24)
y = int(math.sin(anguloRadianes) * 24)
if seno_normal:
oled.pixel(x + 24, y + 32, 1)
else:
oled.pixel(-x + 24, -y + 32, 1)
oled.hline(0, 32, 128, 1)
oled.vline(49, 0, 64, 1)
oled.line(24, 32, xLinea + 24, yLinea + 32, 1)
oled.hline(xLinea + 24, yLinea + 32, 27 - xLinea, 1)
oled.show()
if not freeze_display:
oled.scroll(1, 0)
oled.fill_rect(0, 0, 51, 64, 0)
# Control de los interruptores
if not switch_func.value():
seno_normal = not seno_normal
sleep(0.2) # Pequeña pausa para evitar cambios rápidos debido a rebotes del interruptor
if not switch_freeze.value():
freeze_display = not freeze_display
sleep(0.2) # Pequeña pausa para evitar cambios rápidos debido a rebotes del interruptor