Little Robot Friends
Arduino Library Reference
version 1.1
|
This tutorial uses example code found in:
MyLRF02_Say.cppCongratulations, you’ve made the eyes on your Little Robot Friend blink, wink and change colours. Next step is to give your Little Robot Friend a voice. Let’s make some sounds!
Making unique sounds is very similar to making light patterns. Sounds are created using a similar ‘struct’, however this time we’ve got a couple more options that will need to be included. We tried to make Little Robot Friend sounds in a way that mimics how we say words. We can control and customize your Little Robot Friend’s voice using the LRFSound object.
Each LRFSound is comprised of the following LRFSound values: LRFNote, LRFOctave, LRFIntonation and LRFDuration. If you play an instrument or study music theory, you’ll be familiar with these terms already. If not, don’t worry - here’s a quick explanation of each value:
Check out the links below to learn more about the LRFSound and its options: LRFNote, LRFOctave, LRFIntonation and LRFDuration
Let’s start by making our robot play a single note, in this case, a C.
Once we've created our pattern, we can call it using the API function lrf.say(mySound). This function takes our pattern variable mySound
and plays it. Your robot should play a single note that lasts about (1) second(s) and rises slightly as if it were asking a question. Let's put this in our setup()
function so it happens when the robot starts up:
Cool! Now let’s see if we can make our robot sing a little tune. We can do this by adding more values to mySound
, thus creating an array. Be sure to indicate the number of lines in your array next to the name of your variable. In this example, it’s 3. (You’ll notice that the structure of the code is a bit different than in Tutorial 1. This is to make the code cleaner and easier to read so you don’t get all your values mixed up. )
Now, plug your variable mySound into your setup()
function and you should get something that looks like this:
Your robot will play a sequence of 3, (1) second(s) notes. Notice that this time, we used LRFIntonation_Flat value. How did that change the sound? Play around with the values and see what happens.