You may now possess a sense of fulfilment because Max:Bot can go to anywhere you want it to go. But have you feel a little bit more frustrated that there always has something to block its way, like a desk or a closet. Donāt worry, in this chapter, we will teach Max:Bot how to avoid these obstacles.Ā Ā

šø Goals:
1. How to use the Digital Crash Sensor?Ā
2. How to use the āif thenā function?Ā
3. Diagram aided programmingĀ Ā
šø Digital Modules

š 2.1 The āshyā Max:BotĀ
Sometimes, when being touched, Max:Bot will become cute and shy. Yes, he can feel you.

šø Key information

šø Program
ļ¼1ļ¼ Start a new project and name it as āthe shy Max:Bot āĀ
ļ¼2ļ¼ Find the āif thenā function from āLogicā in the function area and place it into the āforeverā loop.Ā

If the logic statement to the right side of āifā is met, the function to the right of "then" should be executed, whereas the next function should be executed if the logic statement is not met. This is an either or thing.
ļ¼3ļ¼ The ā=ā operator lies in the āLogicā.

Besides ā=ā, there are many other operators, like ā>ā, ā

ļ¼4ļ¼ How to control the digital crash sensor?Ā
Anytime when Max:Bot is touched by others, he will immediately become a shy robot. Why he becomes so sensitive? Because we have connected digital crash sensors to it.Ā
Ā In this part, the ādigital readā function will be applied to determine whether the digital crash sensors are touched or not. Connect one of the digital crash sensors to Pin13.Ā Ā Ā

Do you have any idea about what response Max:Bot is going to make? The table below can be used as a reference.Ā

ļ¼5ļ¼ Make the heart beatĀ
Ā Once has being touched by others, Max:Bot will immediately become shy and with his heart speeds up. But how can we make his heart really beat? The function āshow iconā does the job. You can find it in āBasicā of the function area.Ā

As has shown in below image that there is a micro triangle lies at the top right of the āshow iconā. Click it and choose the smaller heart icon.Ā

To make it more like a real heartbeat, we need to add the āpauseā function and another bigger heart icon. By putting together all the functions listed above, we will have the following program.Ā

ļ¼6ļ¼ Download the program to Max:Bot .Ā
Now when you touch Max:Bot , he will then show you his heartbeat. What a cute robot!Ā

šø Exercise
Needless to say, Max:Bot is a very nice companion. We have already created his heartbeat. Now we want to make him a smile face when he is untouched.Ā
We will use the āif elseā function to make him smile. You can also find it in āLogicā of the function area.Ā

Compared with the āif thenā, there is an additional āelseā in the āif elseā. What is it?Ā
As we have learnt in previous part that, in the āif thenā function, If the logic statement to the right side of āifā is met, the function to the right of "then" should be executed, whereas the next function should be executed if the logic statement is not met.Ā Ā
While in the āif elseā function, if the logic statement on the right side of āifā is not met, the statement to the right of āelseā should be executed.
š 2.2 escape the maze
Since the digital crash sensor grows Max:Bot to a sensory robot, what if we place him in a maze? Will he himself find a way out?Ā

šø Key information

šø Program
ļ¼1ļ¼ Start a new program and name it as āescape the mazeāĀ
ļ¼2ļ¼ Help Max:Bot to escape the mazeĀ
Before programming, we should first get to know what Max:Bot would do for avoiding obstacles.Ā
If the left digital crash sensor is touched, Max:Bot will then turn to the right;Ā
If the right digital crash sensor is touched, Max:Bot will then turn to the left.Ā
The diagram below can be taking as a guidance:Ā


ļ¼3ļ¼ Some above learnt programs will be combined in this part to helpĀ
Max:Bot escape the maze. Such as: turn left, turn right, go straight, etc. By putting all the programs mentioned above together, we have the final program as below:Ā
Please note: Different batteries output different voltages. So the value below in the āpauseā function is just used for a reference. You have to try and adjust them based on the actual situation.Ā

šø Exercise
Max:Bot , a really fast learner, now has made another step forward! Can you remember the āheartbeatā we made for him? How about to make him show us his direction when he is ready to turn.Ā
š”Tips: You may need the help of the āshow ledsā function.Ā Ā Ā









