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.
20 lines
511 B
Python
20 lines
511 B
Python
# Timer Control Example
|
|
#
|
|
# This example shows how to use a timer for callbacks.
|
|
|
|
import time
|
|
from pyb import Pin, Timer, LED
|
|
|
|
blue_led = LED(3)
|
|
|
|
# we will receive the timer object when being called
|
|
# Note: functions that allocate memory are Not allowed in callbacks
|
|
def tick(timer):
|
|
blue_led.toggle()
|
|
|
|
tim = Timer(4, freq=1) # create a timer object using timer 4 - trigger at 1Hz
|
|
tim.callback(tick) # set the callback to our tick function
|
|
|
|
while (True):
|
|
time.sleep(1000)
|