Duration – 90 min
Difficulty: – MEDIUM
Introduction
Our robot head can talk (with a little help of LOFI Blocks app). What is more it can talk in eight foreign languages! In this lesson we will teach our LOFI Robot to introduce itself.
Preparation
Modules:
- LOFI Brain controller
- Button module
- Potentiometer module
- Light sensor module
- Green LED module
- Red LED module
- Servo motor
- USB cable
Conections:
- Servo motor → OUTPUT1
- Green LED -> OUTPUT3
- Red LED -> OUTPUT4
- Distance sensor -> DISTANCE socket
- Button module -> INPUT1
- Light sensor -> INPUT3
- Power supply → USB cable → USB port
Potentiometer module -> INPUT2
Lesson
Say “Hello!”
Lets start with something simple make the robot introduce itself. Pick SAY block from SPEECH category. Remember to add WAIT block afterwards otherwise the code will be constantly repeating and starting saying “Hello!” bfrom the beginning without saying the whole word.
Our robot has few nifty sensors so lets use them to add some interaction. For example we could use distance sensor so the robot will be saying HELLO only when it sees something closer than 10cm away.
Please do not push me!
Our robot might be kind but he can also be assertive. We can detect when it is touched by reading the button module press. If the button is pressed the robot will nod it`s head and say “Do not push me!”
Button module is connected to INPUT1, normally it`s signal state is around 0-5 but when you press the button reading rise up to 100 so we can use firmly assume that the button is pressed when reading from INPUT1 is greater than 90.
For the sake of readability I removed code from previous example but you can simply add new function below the previous ones.
Now when the robot detects user pressing the button few things happen:
1. Robot says “Please do not push me!
2. Servo on INPUT1 is turned to position 40 then 60 and all this is repeated 2 times – this makes robot nodding his head twice
3. After nodding head is set forward – set servo to 50
4. Green (OUTPUT3) and Red LED (OUTPUT4) turn on for two seconds
5. When the button is not pressedLEDs turn off
It is getting dark in here
In a similar fashion we can use the light sensor so our robot knows when it got dark and turns on it`s lights.
When reading from light sensor (INPUT3) falls below 10, turn the LEDs on … else … turne the LEDs off.
Do the dance
We have one last sensor on our robot head to use – a potentiometer. We can use the built-in LOFI Brain buzzer and make it beep along with rythmically moving robot head in tempo set by potentiometer.
Now if the potentiometer is set below 20 our robot will start nodding its head and make serial beeps in a tempo dictated by the potentiometer as it is a parameter of WAIT blocks.