@vze3 思路就是记录最新的找到色块的时间,然后判断当前时间是否超过1000ms。
import sensor, image, time, math
import pyb
led = pyb.LED(1)
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()
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()
if pyb.millis() - last > 1000:
led.off()
else:
led.on()