logo

无论是高电平 还是低电平 蜂鸣器一直闷响

2023-05-30 09:56
P
u2gf
01b4d912-82bd-483c-b3c5-10747eacae59.jpg
ae6fa1c6-bc95-488e-a79d-7add0b52e471.jpg
2023-05-31 19:40
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

2023-06-03 10:45
P
u2gf
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)
P
u2gf

没有报错,就是蜂鸣器一直闷响:crying_cat_face:

2023-06-06 16:59
I
网红小智智 星瞳科技

1,先不连接OpenMV,单独测试蜂鸣器,看看蜂鸣器是否正常。

2,单独写控制IO高低电平的程序,测试蜂鸣器是否正常。