logo

如何让led灯亮固定的次数呢?

2022-07-06 13:26
Z
vze3

不用延时函数的话?

2022-07-06 20:52
I
网红小智智 星瞳科技
import sensor, image, time, math
import pyb

thresholds = [(30, 100, 15, 127, 15, 127)]

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()

from pyb import Pin, Timer, LED

led  = LED(1)

# we will receive the timer object when being called
# Note: functions that allocate memory are Not allowed in callbacks
def tick(timer):        
    led.toggle()
    
tim = Timer(2, freq=10)

last = -1000
while(True):
    clock.tick()
    img = sensor.snapshot()
    blobs = img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200, merge=True)
    print(blobs)
    if blobs:
        last = pyb.millis()
        led.off()
        tim.init(freq=10)
        tim.callback(tick)
    if pyb.millis() - last > 1000:
        tim.deinit()
        led.off()
2022-07-07 20:09
Z
vze3

@kidswong999 这个代码运行了是识别到色块后led灯一直亮,然后移开色块又会亮两次。

我的意思是识别到色块亮两次,然后没有色块就熄灭?

2022-07-07 20:56
I
网红小智智 星瞳科技

那你直接sleep就完事了。

2022-07-10 15:02
Z
vze3

@kidswong999 可以不用sleep吗,那该怎么写?

2022-07-11 16:08
I
网红小智智 星瞳科技

@vze3 为什么不用sleep?理由呢?

2022-07-12 12:07
Z
vze3

@kidswong999 用sleep帧率会降低蛮

2022-07-12 20:32
I
网红小智智 星瞳科技

@vze3 降低就降低啊,反正你的逻辑也用不到那么高帧率。