from machine import Pin
import utime
import math
# Configuracion de los pines GPIO
# el orden corresponde D0=2, D1=3 ...D6=9 y D7=10
pines = [2, 3, 4, 5, 6, 7, 8, 9, 10]
def GPIO_SALP(valor, listagpio):
pines_gpio = [Pin(pin, Pin.OUT) for pin in listagpio]
ii = 1
saltxt = ""
for i in range(8):
if valor & ii:
pines_gpio[i].value(1)
saltxt = saltxt + "1"
else:
pines_gpio[i].value(0)
saltxt = saltxt + "0"
ii = ii << 1
return saltxt
def SerieFourier_1(nmax):
xmin = 0.0
xmax = 59.0
fx = 0.0
delta = 0.5
sum_val = 0.0
T = 60
x = xmin
while x <= xmax:
sum_val = 0
a0 = 0.0
w0 = 2 * math.pi / T
for n in range(1, nmax, 1):
an = 0.0
bn = (2 / (math.pi * n)) * (1 - math.pow(-1, n))
sum_val += (an * math.cos(n * w0 * x) + bn * math.sin(n * w0 * x))
fx = a0 / 2 + sum_val
print(fx + 2)
GPIO_SALP(int(fx + 2), pines)
x += delta
# Bucle principal del contador
contador = 0
while True:
for narmonicos in range(1, 100, 1):
SerieFourier_1(narmonicos)