from machine import Pin
import utime
import math
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
for i in range(8):
pines_gpio[i].value(1 if (valor & ii) else 0)
ii = ii << 1
def SerieFourier_EjProp1(nmax):
"""
f(x) = 0 para -pi < x < 0
f(x) = pi - x para 0 <= x < pi
a0 = pi/2
an = (1 - (-1)^n) / (n^2 * pi)
bn = 1/n
"""
xmin = 0.0
xmax = 59.0
delta = 0.5
T = 60
x = xmin
while x <= xmax:
w0 = 2 * math.pi / T
a0 = math.pi / 2
sum_val = 0.0
for n in range(1, nmax + 1):
an = (1 - math.pow(-1, n)) / (n * n * math.pi)
bn = 1.0 / n
sum_val += an * math.cos(n * w0 * x) + bn * math.sin(n * w0 * x)
fx = a0 / 2 + sum_val
print(fx)
GPIO_SALP(int(fx * 20 + 128), pines) # escala para 8 bits
x += delta
while True:
for narmonicos in range(1, 30, 1):
SerieFourier_EjProp1(narmonicos)