利用Timer和GPIO实现openMV跑马灯,点亮openmv的led灯是开启openmv的基础中的基础程序。
在官方例程的基础上,我们使用Timer定时器,实现红绿蓝三色灯的变换。
通过
整体逻辑比较简单,用一个if判断,当前的Led引脚赋值,加计时器功能就可以了。
from fpioa_manager import fm
from Maix import GPIO
from machine import Timer
import time
def on_timer(timer):
print("time up:",timer)
print("param:",timer.callback_arg())
tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=1, unit=Timer.UNIT_S, callback=on_timer, arg=on_timer, start=False, priority=1, div=0)
print("period:",tim.period())
tim.start()
time.sleep(5)
tim.stop()
#12 13 14 led灯分别为红绿蓝色,用系统时间间隔实现跑马灯
io_led_red = 12
while True:
if(io_led_red ==15):
io_led_red=12
fm.register(io_led_red, fm.fpioa.GPIO0)
led_r=GPIO(GPIO.GPIO0, GPIO.OUT)
led_r.value(0)
tim.restart()
time.sleep(1)
tim.stop()
io_led_red=io_led_red + 1