import sensor, image, time
import pyb, math
green_threshold = ( 0, 80, -70, -10, -0, 30)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
last_time = None
last_blob = None
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([green_threshold])
if blobs:
blob = blobs[0]
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
now_time = pyb.millis()
if last_blob:
diff_time = now_time-last_time
diff_position = math.sqrt((blob.cx()-last_blob.cx())**2 + (blob.cy()-last_blob.cy())**2)
print(diff_position, diff_time)
last_time = now_time
last_blob = blob