# Untitled - By: dell - Tue Aug 6 2024
import sensor, image, time
import sensor, image, time
from pyb import UART
from pyb import Timer
from pyb import LED
from pyb import Pin
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
#PB10,PB11
uart = UART(3, 9600, timeout_char=200)
clock = time.clock()
led_board_E3 = Pin('E3', Pin.OUT, Pin.PULL_NONE)
TaskFlag=-1
def Uart_Receive(): #UART接收 改变框小球的颜色阈值
global TaskFlag
temp_data0 = uart.readchar()
if temp_data0==0x55: #帧头相等
FunNum = uart.readchar() #再读下一个
print(FunNum)
if FunNum ==0x01:
TaskFlag =1
led_board_E3.off() #用状态灯指示
elif FunNum ==0x02:
TaskFlag =2
led_board_E3.on()
def tick(timer): # we will receive the timer object when being called
global TaskFlag
if uart.any():
Uart_Receive()
#开机闪烁LED灯几次
#led_board_E3.on()
#time.sleep_ms(200)
#led_board_E3.off()
#time.sleep_ms(200)
#led_board_E3.on()
#time.sleep_ms(200)
#led_board_E3.off()
#time.sleep_ms(200)
#led_board_E3.on()
#time.sleep_ms(200)
#led_board_E3.off()
#time.sleep_ms(200)
#led_board_E3.on()
#time.sleep_ms(200)
#led_board_E3.off()
#time.sleep_ms(200)
#led_board_E3.on()
#time.sleep_ms(200)
#led_board_E3.off()
#time.sleep_ms(200)
#设置定时器,以及定时频率
tim = Timer(4, freq=50) # create a timer object using timer 4 - trigger at 5Hz
tim.callback(tick) # set the callback to our tick function
while(True):
clock.tick()
img = sensor.snapshot()
if TaskFlag==1 : #如果是第一个功能,发送二维码数据
print('task01:',TaskFlag)
time.sleep_ms(100)
if TaskFlag==2 : #如果是第2个功能,发送颜色数据的位置
print('task02:',TaskFlag)
time.sleep_ms(100)
print(clock.fps())
在这里插入图片描述