What if…..#
Programming
30 min
1#
Now that we are able to read the values from the sensors, we can start using it and let the robot react to it. In this workshop you will learn about the basics of programming. You will program a robot that stops when it sees a line.
2#
The programming of the robot of course happens at the ‘Programming’ tab. In the previous workshop you have read the value of the sensor once.
This of course is something we want to do continuously. We can achieve this by using ‘loops’. You can add one of these around your existing blocks and press ‘play’.
3#
4#
LET OP
In case you are reading sensor values inside the ‘while true’ block, you also have to add a ‘wait’ block. If you forget that one, your robot will try to read the values so quickly that it is not able to catch up. If you forget to add it, you will notice that your sensor values will not be up-to-date anymore and you will receive old values.
5#
6#
In order to make the robot stop at a black line, we need to add a ‘if-else’ blok. This block makes sure that the robot does something based on a certain condition.
This example code will detect if the robot sees a black line or not. You can move your robot over the black line and check if it indeed sees it.
BE CARFEUL
The values of whether it is black or not might be different. So you have to find this yourself.
7#
You will probably run into a situation every now and then where your program is not working the way you intended it to work.
In these cases it could be useful to pause your program and go through it step by step. This is called ‘debugging’. You can debug a Mirte program by clicking the ‘pause’ button:

Your program will stop and highlight the block where the code will continue.
You will see a similar thing in Python, only not highlighted, but with a red arrow in front on the line. You can execute that line/block by pressing the ‘step’ button:

The robot will only execute that single line/block and pause again. In this way you can easily follow the steps your program is doing.