mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
* Add Arduino UART example. * Update Arduino SPI example to use callbacks. * Remove printf from timer_control.py callback. * Add PWM channel 3 and servo 3 to pwm and servo examples.
16 lines
524 B
Python
16 lines
524 B
Python
# PWM Control Example
|
|
#
|
|
# This example shows how to do PWM with your OpenMV Cam.
|
|
|
|
import time
|
|
from pyb import Pin, Timer
|
|
|
|
tim = Timer(4, freq=1000) # Frequency in Hz
|
|
# Generate a 1KHz square wave on TIM4 with 50%, 75% and 50% duty cycles on channels 1, 2 and 3 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)
|
|
ch3 = tim.channel(3, Timer.PWM, pin=Pin("P9"), pulse_width_percent=50)
|
|
|
|
while (True):
|
|
time.sleep(1000)
|