

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片
import sensor, image, time, math, lcd
from pyb import UART #串口
from pyb import Pin
import json
import machine
threshold_index = 3 # threshold_index的数值对应了列表thresholds[]中的色块LAB
thresholds = [(19, 100, -68, -6, -35, -5), #深蓝色
(17, 100, -50, -1, -27, -2),#浅蓝色
(92, 62, -6, 38, 38, -13), #粉色
(30, 66, -2, -32, -29, -11)] #白色
buzzer = Pin('P0', Pin.OUT_PP)
buzzer.low()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA2)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # 关闭白平衡
sensor.set_auto_whitebal(False) # 关闭自动增益
clock = time.clock()
lcd.init() #初始化LCD
uart = UART(3, 115200) #初始化串口
uart.init(115200, bits=8, parity=None, stop=1) #8位数据位,无校验位,1位停止位、
while(True):
clock.tick()
img = sensor.snapshot()
blob = img.find_blobs([thresholds[threshold_index]], area_threshold=300)
text = 2;
if blob: #如果找到了目标颜色
text = 1
if text == 1:
print("MASK YES")
uart.write("MASK YES")
buzzer.low()
for b in blob:
#迭代找到的目标颜色区域
img.draw_rectangle(b[0:4]) # rect
img.draw_cross(b[5], b[6]) # cx, cy
img.draw_string(35, 70, "MASK!!")
if text == 2:#如果没有找到口罩
print("ON MASK")
uart.write("ON MASK")
img.draw_string(35, 70, "NO MASK!!")
buzzer.high() # 蜂鸣器响
#time.sleep(200) # 延时200毫秒
#buzzer.low() # 停止蜂鸣器
lcd.display(img)没有报错,就是蜂鸣器一直闷响:crying_cat_face:
1,先不连接OpenMV,单独测试蜂鸣器,看看蜂鸣器是否正常。
2,单独写控制IO高低电平的程序,测试蜂鸣器是否正常。