Page 6 of 16
Page 114
import esp32
from machine import Pin
import machine
pin=Pin(4,Pin.OUT,value=0)
rmt=esp32.RMT(0,pin=pin)
t=20000000 # pulse repetition in us
d=[10,20,30,40,50] #duty cycles in percent
times=[]
for p in d:
times.append(int(t*p/100))
times.append(int((t*(100-p)/100)))
rmt.loop(True)
rmt.write_pulses(times,1)
Page 117
from machine import Pin, PWM
import array
import math
wave = array.array('H', [0]*256)
for i in range(256):
wave[i] = int(65535//2 + (math.sin(i * 2.0 * 3.14159 / 256.0) * 65535//2))
pwm1 = PWM(Pin(4),freq=300000)
print(pwm1)
while(True):
for i in range(256):
pwm1.duty_u16(wave[i])
print(pwm_get_wrap(0))
while(True):
for i in range(256):
pwm16.duty_u16(wave[i])
Page 119
from machine import Pin, PWM
from time import sleep_ms
pwm1 = PWM(Pin(4),freq=2000)
while True:
for d in range(0,65535,655):
pwm1.duty_u16(d)
sleep_ms(50)
Page 120
from utime import sleep_ms
from machine import Pin, PWM
pwm1 = PWM(Pin(4),freq=2000)
while True:
for b in range(0,100):
pwm1.duty_u16(int(65535*b*b*b/1000000))
sleep_ms(50)