Embedded_game/002_B_Car/scan_qr_code.py

50 lines
1.2 KiB
Python
Raw Normal View History

2025-01-02 12:48:11 +08:00
#实验名称:二维码识别
#版本v1.0
#日期2019-12-23
#翻译和注释01Studio
import sensor,lcd,time
from machine import Timer, PWM, UART, Timer
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(9)
#摄像头模块初始化
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1) #后置模式
sensor.skip_frames(30)
#lcd初始化
lcd.init()
clock = time.clock()
while True:
clock.tick()
img = sensor.snapshot()
res = img.find_qrcodes() #寻找二维码
# if len(res) > 0: #在图片和终端显示二维码信息
for i in res:
img.draw_rectangle(i.rect())
img.draw_string(2,2, i.payload(), color=(0,128,0), scale=2)
print(i.payload())
lcd.display(img)
print(clock.fps())