如何让led灯亮固定的次数呢?
-
不用延时函数的话?
-
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()
-
@kidswong999 这个代码运行了是识别到色块后led灯一直亮,然后移开色块又会亮两次。
我的意思是识别到色块亮两次,然后没有色块就熄灭?
-
那你直接sleep就完事了。
-
@kidswong999 可以不用sleep吗,那该怎么写?
-
@vze3 为什么不用sleep?理由呢?
-
@kidswong999 用sleep帧率会降低蛮
-
@vze3 降低就降低啊,反正你的逻辑也用不到那么高帧率。