Course 5 / Lecture 1:

Displaying emotions, playing sounds

This lecture is about using the display and the built in speaker of the robot for communication. You will learn how to display emojis on the LCD display, and you will also learn how to notify the user of the robot using sounds if a certain event occurs. You will write a program, that will show a sad face on the LCD screen and play a buzzer sound in case the robot hits the wall.

Figure 1 - Ozeki Sniffer


Task #1:

Create an entry point, and start the motors that are connected to your robot!

Step 1: Create the entry point

In SNAP, the most of the cases the entry point of the program is a Control block. In this menu, there are many blocks that can be used as a trigger to start your program. You can start your program by pressing a key or by sending a message. In this particular case, you will use the block 'when green flag clicked' like Figure 2 demonstrates. That means the program starts when you press the green flag in the top right corner or you click directly the block that you dragged to the script.

Figure 2
Figure 2 - Entry point of a SNAP program

Step 2: Start the motors of your robot

In this step, the robot should move forward. For that you need to tell the motors of the robot to start rotating. You can reach that by adding a 'Start motor' block where you can choose which motors and what power percentage you want to start moving the robot. Minus numbers mean that your robot will go backward. In this case, the motors are connected to A and B ports of the EV3 Brick, and the driving force is 20%. By adding that block to the previously dragged control block, your robot is going to roll on its wheels till you stop the motors. You can find this block in the Lego motors.

Figure 3
Figure 3 - Adding of the 'Start motor' block

Task #2:

Check the distance to the wall with the ultrasonic sensor, and stop the robot when it is too close to that!

Step 1: Measure the distance to the wall

In the previous task, you started your robot. Now it is time to stop it when it is close enough to the wall or some obstacle. By using the 'wait until' block found in Control category, the execution process will wait until the condition in the block becomes true. During this time, the robot will go forward continuously. The condition will be that if the sensor is closer than 5 centimeters to an object. To do this, please drag a green '<' block from the Operators category then add the 'Distance in cm' block to the left side of the green '<' block. You should use the Ultrasonic Sensor of the robot for distance measurement, so please select its connection for the previous red block as you can see on Figure 4. To the right side of the green '<' block just type 5 like 5 centimeters.

Figure 4
Figure 4 - Checking of the Ultrasonic Sensor

Step 2: Stop the robot

If the robot is too close to the wall or other object, the control of the program will move forward to the next block which in this case would be the 'Stop motor' block. This block guarantees that the Sniffer's motors will stop when it has come close to any kind of obstacle. This block can be found in the Lego category and it has got an option where you can choose which motors you want to stop. As mentioned in the previous step above, the Sniffer's motors are connected to A and B ports of the Lego Brick, so you need to choose 'A+B' option for 'Stop motor' block (Figure 5).

Figure 5
Figure 5 - Now the robot stops if it is close to the wall

Task #3:

Draw an emoji on your robot's LCD display, and send a 'beep' command to its speaker!

Step 1: Draw an emoji on LCD display

The next block that you have to add is going to draw an emoji on the Sniffer's LCD display. This block name is 'Drawing [emoji] on LCD' and it is available in the Lego category as you can see on Figure 6. Using this block you can select from the large volumes of emojis that can be placed on your robot's display because it contains a drop-down menu for the emojis. Now at the end of this step, your robot will stop and display the emoji you chose before when it come close to the wall.

Figure 6
Figure 6 - Now the robot stops and display emoji if it is close to the wall

Step 2: Play the tunes

The last block will have the functionality to play a predefined sound file. The procedure of adding this block is the same as the previous ones so you just need to drag it into the statement. This block is called 'To [connection], message: [command]'. You can find it in the Ozeki category. This block has also got a drop-down menu where you need to select the speaker of the robot. And then type one of the available command for the speaker. In this case, the 'beep' command was entered. Now you have a complete program (Figure 7) which can give you a feedback from the robot.

Figure 7
Figure 7 - The complete program

Program code

Figure 8 - Program code for displaying emojis and playing sounds

More information


Copyright © 2000- |Ozeki Ltd | |
Page: 6044 | | Login
Thank you for visiting this page