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()