Have you ever chatted with iphoneās Siri or interact with a smart robot? If not, thatās ok, cause now we can directly program an intelligent chatbot by ourselves with mind+ and micro:bit. Isnāt that sounds cool! Well, letās begin.
The AI translations will be involved in this chapter, also we will get to know about the temperature sensor on the micro:bit board.
6.1 Get to know list
We have already get known about variable, you may find that there is a ācreate a listā block in the variable module. What is a list ? we know that a variable can be used to store number, char etc and can be refereed repeatedly. Of course, we can also update a variable. In fact, a list is a collection variable, just like a queue. For example, we create a list and name it as āpresentā, then place four items in the present list: crystal ball, music box, lego, model car. We can add items into the list, here we add an item to the end of the list, and then the list would be like this ācrystal ball, music box, lego, model car, doll houseā. Besides, the items in the list can be revised, for instance, change the first item into dinosaur model, then the list would be ādinosaur model, music box, lego, model car, doll houseā. Apparently, we can delete items in the list. Well now, letās create a list and see what functions will be found in blocks. As figure 6-1 shows, we can add or delete a specified item to a list; replace an item, hide or show a list.
Case 1: Santa Claus gives gifts
In this case, we are gonna create three sprites: Santa Claus, a boy and a girl, as figure 6-2 shows. The boy and girl asked Santa Claus respectively āwhat can I get for my Christmas present?ā Santa Claus thinks for a while and then determines to pick a gift randomly from his pocket. But here comes a problem: there are crystal ball and Transformer in his pocket, so a situation like this could happen: the crystal ball was sent to a boy and the Transformer went to a girl, then it would be awkward! To deal with that problem, we need to classify our gifts into For Girl and For Boy. Cause it could be much reasonable to pick a present from For Girl
list when a girl asked for her gift.



In this case we learned how to create a list, add items for the list, hide and acquire a certain item form the list and so on. We will use a new block

here . It can be found in āOperatorsā module. The block concatenates or ālinksā the two values together and reports the result.
Case 2: Chat Language Detection
We will use list to detect chat language in this case. The functions the programs need to realize: obtain a speech the user input, divide it into single character and put them into a list, then check every item in the list.
First of all, we need to learn how to get the number of characters.

Secondly, divide a speech into single characters and place the characters into a list.
Input a speech āI am Mickoā, the number of characters is 3, and it needs three times to get all the characters. Set a variable āiā to represent the number of cycles. Get the first character in the first loop and so on. The value of i will increase by 1 in every loop. When it comes to the last loop, the value of i will be 4 after getting the third character. Then stops the loop and display the content of the list.

Character Detection
Input āI am Mickoā and check the result. So far, we can detect some particular characters of the chatting language.
With the knowledge of list we can make much more fun programs, detect language, chatting room and so on. Ok, now letās start to make the chatbot.

6.2 Algorithms Analysis
- Create a list āChatbotā and show it;
- Repeatedly run the program āask ⦠and waitā, and āanswerā. Add āanswerā to the end of the list to make it like an effect of asking question.
- Embed the āif thenā¦elseā repeatedly and detect if the words like ātimeā, ājokeā, āsongā, ātranslationā, and ātemperatureā includes in the āanswerā.
6.3 Programming
We can ask the chatbot to tell us time, temperature, or let him tell jokes, play music and do translations. The scripts are shown in figure 6-7.
You can play the sound in the sound library, record your own sound or upload a sound file from your computer. We use the sound ādance aroundā in the loops of the sound library.


Load the google translate: click āExtensionsā-> āFunctionā-> āGoogle Translateā. Then we can use the related google translate module.

6.4 Temperature Sensor
Connect micro:bit and the computer with micro USB. The temperature sensor on the micro:bit board will detect the current temperature of the device. (unit: °/ā)

6.5 Programming Result
Click the green flag to start the program, and check the effect. We can drag the frame of the list to expand the display area.


6.6 Training Camp
Now the chatbot can only realize the function of chatting, but we can combine it with the micro:bit to simulate the smart home, for example, to give orders like āturn on/off the lightā to control the LED light on the micro:bit board.









