# -*- coding:utf-8 -*- # @Author len # @Create 2023/12/4 19:25 import sensor import image import lcd import 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(-75) THRESHOLD = (5, 70, -23, 15, -57, 0) clock = time.clock() lcd.init() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) #sensor.set_vflip(1) #开启图像反转 sensor.set_vflip(0) #关闭图像反转 sensor.run(1) sensor.skip_frames(30) min_degree = 0 max_degree = 179 while True: clock.tick() img = sensor.snapshot() for l in img.find_lines(threshold = 2000, theta_margin = 25, rho_margin = 25): if (min_degree <= l.theta()) and (l.theta() <= max_degree): img.draw_line(l.line(), color = (255, 0, 0)) lcd.display(img)