#!/usr/bin/env python3
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.sound import Sound
from ev3dev2.sensor.lego import ColorSensor
from time import sleep
from ev3dev2.display import Display
from threading import Thread

lcd = Display()
cl1 = ColorSensor('in3')
cl2 = ColorSensor('in2')
ts = TouchSensor()
sound = Sound()

ts.wait_for_pressed()
sound.beep()
sleep(1)
sound.beep()
sleep(1)
sound.beep() # na tretí zvukový signal pustiť telesá,v ten istý čas

y = 0
x = 0
final1 = 0
final2 = 0
state = 0
teleso__1 = 0
teleso__2 = 0
seconds = float(0)

def time():
    global seconds
    while True:
        seconds += .1
        time.sleep(.1)

def teleso_1():
    global x
    while True:
        x = cl1.reflected_light_intensity

def teleso_2():
    global y
    while True:
        y = cl2.reflected_light_intensity
def count():
    global final1
    global teleso__1
    global seconds
    global x
    while final1 == 0:
        if x > 6:
            teleso__1 = seconds
            final1 = 1
def count2():   
    global final2
    global teleso__2
    global seconds
    global y
    while final2 == 0:
        if y > 6:
            teleso__2 = seconds
            final2 = 1


def print_():
    global teleso__2
    global teleso__1
    while True:
        lcd.update()
        sleep(1)
        lcd.clear()
        lcd.text_pixels(str(teleso__1),str(teleso__2),False,45,25,font = 'courB24')
  
if __name__ == '__main__':
    Thread(target = time).start()
    Thread(target = teleso_1).start()
    Thread(target = teleso_2).start()
    Thread(target = teleso_1).start()
    Thread(target = count).start()
    Thread(target = count2).start()
    Thread(target = print_).start()



