Page 5 of 15
Page 116
from machine import Pin, PWM
pwm1 = PWM(Pin(4),freq=250)
pwm2 = PWM(Pin(2),freq=250)
pwm1.duty_u16(65535//2)
pwm2.duty_u16(65535//4)
pwm1 = PWM(Pin(4),freq=250)
pwm2 = PWM(Pin(2),freq=250)
pwm1.duty_u16(65535//2)
pwm2.duty_u16(65535//4)
Page 117
import time
from machine import Pin, PWM
pwm1 = PWM(Pin(4),freq = 50)
while True:
pwm1.duty_u16(65535//2)
time.sleep_ms(19)
pwm1.duty_u16(65535//4)
time.sleep_ms(19)
Page 118
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 119
import time
from machine import Pin, PWM
pwm1 = PWM(Pin(4),freq = 20000000)
pwm1.duty_u16(65535//4*2 +2)
from machine import Pin, PWM
pwm1 = PWM(Pin(4),freq = 20000000)
pwm1.duty_u16(65535//4*2 +2)
Page 121
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 123
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 124
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)