Little Robot Friends
Arduino Library Reference
version 1.1
|
This class is the main class of the LRF API. By importing LRF.h into your code, you are automatically creating an instance of the LRF library stored in the variable lrf
.
All functions listed in this document can be accessed using that static instance, eg:
#include <LRF.h>
Public Member Functions | |
void | setup (void) |
setup the LRF library | |
void | loop (void) |
run the LRF library loop | |
Expressions (Lights and Sounds) | |
void | blink (LRFPattern pattern) |
Blink a light pattern on the LED eyes. More... | |
void | blink (LRFPattern pattern, unsigned int duration) |
Blink a light pattern on the LED eyes. More... | |
void | say (LRFSound sound) |
Speak a single sound. More... | |
void | blinkAndSay (LRFPattern pattern, LRFSound sound) |
Blink and speak at the same time. More... | |
void | blinkAndSay (LRFPattern pattern, LRFSound *sounds, char soundCount) |
Blink and speak at the same time. More... | |
Events | |
void | setEventHandler (LRFEvent event, LRFEventHandler handler) |
Customize how your robot responds to particular events. More... | |
System | |
void | setBoredom (unsigned int timeout, unsigned char count) |
Set how quickly and how often your robot gets bored. More... | |
void | sleep (void) |
Put the robot to sleep. More... | |
Infrared | |
LRFIRMessage | readIRMessage (void) |
Read the latest received IR message. More... | |
void | sendIRMessage (LRFIRMessage message) |
Send an IR message. More... | |
Sensors | |
unsigned char | readTouch (void) |
Read the touch sensor. More... | |
unsigned char | readLight (void) |
Read the light sensor. More... | |
unsigned char | readMicrophone (void) |
Read the microphone. More... | |
Outputs | |
void | setLeftLED (unsigned char red, unsigned char green, unsigned char blue, bool update=true) |
Set the RGB value of one or both LEDs. More... | |
void | setRightLED (unsigned char red, unsigned char green, unsigned char blue, bool update=true) |
Set the RGB value of one or both LEDs. More... | |
void | setBothLEDs (unsigned char red, unsigned char green, unsigned char blue, bool update=true) |
Set the RGB value of one or both LEDs. More... | |
void LittleRobotFriend::blink | ( | LRFPattern | pattern | ) |
pattern | Light pattern data object |
duration | Duration of the pattern in milliseconds |
This function causes your LRF’s LED eyes to blink a pattern. This is what is called a ‘blocking function’, meaning that no other code will run while your robot is blinking.
Usage:
LRFPattern myPattern = { LRFColor_Red, LRFColor_Green, LRFPatternMode_Fade }; // make a pattern lrf.blink(myPattern); // blink the pattern for 1s (default) lrf.blink(myPattern, 5000) // blink the pattern for 5s Serial.println("Pattern done!");
void LittleRobotFriend::blink | ( | LRFPattern | pattern, |
unsigned int | duration | ||
) |
pattern | Light pattern data object |
duration | Duration of the pattern in milliseconds |
This function causes your LRF’s LED eyes to blink a pattern. This is what is called a ‘blocking function’, meaning that no other code will run while your robot is blinking.
Usage:
LRFPattern myPattern = { LRFColor_Red, LRFColor_Green, LRFPatternMode_Fade }; // make a pattern lrf.blink(myPattern); // blink the pattern for 1s (default) lrf.blink(myPattern, 5000) // blink the pattern for 5s Serial.println("Pattern done!");
void LittleRobotFriend::say | ( | LRFSound | sound | ) |
sound | Sound data object |
This function causes your LRF’s speaker to say a sound. This is what is called a ‘blocking function’, meaning that no other code will run while your robot is speaking.
Usage:
LRFSound mySound = { LRFNote_C, LRFOctave_3, LRFIntonation_Rising, LRFDuration_Medium, LRFDuration_None }; // make a sound lrf.say(mySound); // speak the sound Serial.println("Sound done!");
void LittleRobotFriend::blinkAndSay | ( | LRFPattern | pattern, |
LRFSound | sound | ||
) |
pattern | Light pattern data object |
sound | Sound data object |
This function causes your LRF to blink and speak at the same time. this is a ‘blocking function’, meaning that no other code will run while your robot is expressing.
Usage:
LRFPattern myPattern = { LRFColor_Red, LRFColor_Green, LRFPatternMode_Fade }; // make a pattern LRFSound mySound = { LRFNote_C, LRFOctave_3, LRFIntonation_Rising, LRFDuration_Medium, LRFDuration_None }; // make a sound lrf.blinkAndSay(myPattern, mySound); Serial.println("Blinkin' and speakin' done!");
void LittleRobotFriend::blinkAndSay | ( | LRFPattern | pattern, |
LRFSound * | sounds, | ||
char | soundCount | ||
) |
pattern | Light pattern data object |
sounds | Pointer to array of sound data objects |
soundCount | Number of sounds in array |
This function causes your LRF to blink and speak multiple sounds at the same time. this is a ‘blocking function’, meaning that no other code will run while your robot is expressing.
You may ask: "Why are there multiple sounds but only one pattern?". After each sound the pattern is 'reset', which means that in some instances it will go back to the same place, except with 'flip' patterns (eg: LRFPatternMode_FadeFlip), which flip the starting and target colors upon reset. If you really want to mix up your patterns, choose one with random colors (eg: LRFPatternMode_RandomFade).
Usage:
LRFPattern myPattern = { LRFColor_Blue, LRFColor_Pink, LRFPatternMode_FadeFlip }; // make a pattern LRFSound mySounds[3] = { { LRFNote_C, LRFOctave_3, LRFIntonation_Rising, LRFDuration_Medium, LRFDuration_Short }; { LRFNote_D, LRFOctave_3, LRFIntonation_Rising, LRFDuration_Medium, LRFDuration_Medium }; { LRFNote_F, LRFOctave_3, LRFIntonation_Falling, LRFDuration_Long, LRFDuration_None }; }; // make your array of sounds lrf.blinkAndSay(myPattern, mySounds, 3); Serial.println("Blinkin' and speakin' done!");
void LittleRobotFriend::setEventHandler | ( | LRFEvent | event, |
LRFEventHandler | handler | ||
) |
event | Event type constant |
handler | Event handler function pointer |
This function allows you to customize how your Little Robot Friend responds to different events. Create a custom event handler function, fill it with code that shows a response, then attach it to a particular event. Easy!
Usage:
void myTapEventHandler(void) // create a custom event handler { lrf.blinkAndSay(myPattern, mySounds, 3); // blink and say your unique expression } lrf.setEventHandler(LRFEvent_Tap, &myTapEventHandler); // attach your handler to the event (you need the ampersand before the handler to make it a pointer
With this example every time you 'tap' your LRF, it will call your custom function!
void LittleRobotFriend::setBoredom | ( | unsigned int | timeout, |
unsigned char | count | ||
) |
timeout | Length of time in seconds between yawns (lower == bores quickly) |
count | Number of yawns before falling to sleep (lower == sleeps quickly) |
This function allows you to set how quickly your robot gets bored and falls asleep. In typical operation, the LRF gets bored when no interaction is detected for around 30-60 seconds (depending on personality). When this happens it 'yawns'. You may notice the sound it makes when it gets bored. After it's yawned 2-4 times (depending on personality) it finally goes to sleep. Now perhaps you want your robot to go to sleep when there is a particular interaction, or you want your robot to never sleep. Here is how:
lrf.setBoredom(999, 200); // high numbers means no yawning, no sleep lrf.setBoredom(10, 1); // low numbers means quick yawning (yawn in 10s, sleep after 1 yawn)
LRFIRMessage LittleRobotFriend::readIRMessage | ( | void | ) |
void LittleRobotFriend::sendIRMessage | ( | LRFIRMessage | message | ) |
unsigned char LittleRobotFriend::readTouch | ( | void | ) |
unsigned char LittleRobotFriend::readLight | ( | void | ) |
unsigned char LittleRobotFriend::readMicrophone | ( | void | ) |
void LittleRobotFriend::setLeftLED | ( | unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue, | ||
bool | update = true |
||
) |
void LittleRobotFriend::setRightLED | ( | unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue, | ||
bool | update = true |
||
) |
void LittleRobotFriend::setBothLEDs | ( | unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue, | ||
bool | update = true |
||
) |