50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
#实验名称:二维码识别
|
||
#版本: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())
|
||
|
||
|