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
- Ozeki Sniffer: Sniffer robot build instructions
- Ozeki 10 installed: Installed Ozeki 10 Robot OS
- Lego connection installed: Installed Lego Bluetooth connection
- SNAP basics: Basic knowlege of the Snap programming language
Create an entry point, and start the motors that are connected to your robot!
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 - Entry point of a SNAP program
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 - Adding of the 'Start motor' block
Check the distance to the wall with the ultrasonic sensor, and stop the robot when it is too close to that!
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 - Checking of the Ultrasonic Sensor
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 - Now the robot stops if it is close to the wall
Draw an emoji on your robot's LCD display, and send a 'beep' command to its speaker!
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 - Now the robot stops and display emoji if it is close to the wall
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 - The complete program
Figure 8 - Program code for displaying emojis and playing sounds
|Download the SNAP program code|
This code shows you how to play multimedia elements on your robot.
It is easier to follow the guide if you have the codes in front of you:
Download the SNAP code for displaying emojis and playing sounds