Update PWM example.

This commit is contained in:
iabdalkader 2016-05-18 18:45:25 +02:00
parent cb0d89205e
commit b0f4ebf0cd

View File

@ -1,25 +1,14 @@
# PWM Control Example
#
# This example shows how to do PWM with your OpenMV Cam.
#
# WARNING: PWM control is... not easy with MicroPython. You have to use
# the correct timer with the correct pins and channels. As for what the
# correct values are - who knows. If you need to change the pins from the
# example below please try out different timer/channel/pin configs.
import pyb, time
import time
from pyb import Pin, Timer
t2 = pyb.Timer(1, freq=1000)
tim = Timer(4, freq=1000) # Frequency in Hz
# Generate a 1KHz square wave on TIM4 with 50% and 75% duty cycles on channels 1 and 2, respectively.
ch1 = tim.channel(1, Timer.PWM, pin=Pin("P7"), pulse_width_percent=50)
ch2 = tim.channel(2, Timer.PWM, pin=Pin("P8"), pulse_width_percent=75)
ch1 = t2.channel(2, pyb.Timer.PWM, pin=pyb.Pin("P0"))
ch2 = t2.channel(3, pyb.Timer.PWM, pin=pyb.Pin("P1"))
while(True):
for i in range(100):
ch1.pulse_width_percent(i)
ch2.pulse_width_percent(100-i)
time.sleep(5)
for i in range(100):
ch1.pulse_width_percent(100-i)
ch2.pulse_width_percent(i)
time.sleep(5)
while (True):
time.sleep(1000)