I am trying to write some code for my EV3 brick. I am really struggling to get multithreading to work. I am using threading module, it throws no error but function that are supposed to run on another thread aren't run at all. My code:
#!/usr/bin/env pybricks
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
import threading
# Create your objects here.
ev3 = EV3Brick()
def color_thread():
print("color_thread")
ev3.light.on(Color.ORANGE)
wait(100)
ev3.light.on(Color.GREEN)
wait(100)
def speaker_thread():
print("speaker_thread")
ev3.speaker.beep(200,100)
wait(100)
ev3.speaker.beep(500,100)
wait(100)
t1 = threading.Thread(target=color_thread)
t2 = threading.Thread(target=speaker_thread)
t1.start()
t2.start()
So the expected output would be:
color_thread
speaker_thread
and some visible and hearable indication (changing lights and making sounds) but output is:
Starting: brickrun --directory="/home/robot/olgojChorchoj_Stropochod" "/home/robot/olgojChorchoj_Stropochod"
----------
----------
Completed successfully.
and no other indication of those two functions running what so ever.
Can you please tell me what am I doing wrong ? thx