import math import sensor, image, time, lcd import binascii from Maix import GPIO from machine import Timer, PWM, UART, Timer from fpioa_manager import fm import KPU as kpu lcd.init() # lcd初始化 # 映射串口引脚 fm.register(6, fm.fpioa.UART1_RX, force=True) fm.register(7, fm.fpioa.UART1_TX, force=True) # 初始化串口 uart = UART(UART.UART1, 115200, read_buf_len=4096) # 初始化摄像头阈值 def canera_init(): # 摄像头模块初始化 sensor.reset() # 复位和初始化摄像头 sensor.set_pixformat(sensor.RGB565) # 设置像素格式为彩色 RGB565 # sensor.set_pixformat(sensor.GRAYSCALE) # 设置像素格式为灰色 sensor.set_framesize(sensor.QVGA) # 设置帧大小为QVGA(320×240) sensor.set_vflip(1) # 后置模式 sensor.skip_frames(30) # # 跳过前30帧 canera_init() def Servo(angle): ''' 说明:舵机控制函数 功能:180度舵机:angle:-90至90 表示相应的角度 360连续旋转度舵机:angle:-90至90 旋转方向和速度值。 【duty】占空比值:0-100 ''' #PWM通过定时器配置,接到IO17引脚 tim_pwm = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM) S1 = PWM(tim_pwm, freq=50, duty=0, pin=17) S1.duty((angle+90)/180*10+2.5) Servo(0) res_QR = [] timeflag = 0 while (timeflag < 30): # for i in range(9): img = sensor.snapshot() # 获取图像 lcd.display(img) # 在LCD显示 TS_QR = img.find_qrcodes() # 再次寻找二维码 for qr in TS_QR: if all(qr.payload() != existing_qr.payload() for existing_qr in res_QR): res_QR.append(qr) timeflag+=1 time.sleep(0.001) print(timeflag) print(len(res_QR)) for res in res_QR: result = res.payload() print(result)