Threads

A thread is a part of program code that can run independently and at the same time as other parts of the program. For example, you could create a thread that controls the motors, while a different thread can watch sensors or user input. Generally speaking, multi-threading is quite a complex topic. You can learn more about threads in the EV3 Basic manual. See also Exercise 1 of the 'Beyond Basics' exercises in the 'Robot Educator' section of this site. To really understand multi-threading, some extra study is recommended.

Here is an example (from Examples.zip that you can download HERE) in which a thread called 'BLINKER' makes the LED flash while the word 'Tick' is displayed 13 (not 12) times on the LCD screen. (Yes, it's also possible to make the LED flash by using FLASH instead of NORMAL but then you have no control over the flash frequency.) When the main program stops running the BLINKER thread also stops.

LCD.Clear()

Thread.Run = BLINKER

Sub BLINKER

    While "true"

        EV3.SetLEDColor("ORANGE","NORMAL")

        Program.Delay(500)

        EV3.SetLEDColor("OFF","NORMAL")

        Program.Delay(500)

    EndWhile

EndSub

For y=0 to 120 Step 10  'loop will run 13 times, not 12

    LCD.Text(1,0,y,1,"Tick")

    Program.Delay(400)  'pause 0.4 seconds

EndFor