Little Robot Friends
Arduino Library Reference  version 1.1
LittleRobotFriend Class Reference

Detailed Description

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:

lrf.blink(myPattern)
lrf.say(mySound)

Definition at line 62 of file LRF.h.

#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...
 

Member Function Documentation

void LittleRobotFriend::blink ( LRFPattern  pattern)
Parameters
patternLight pattern data object
durationDuration of the pattern in milliseconds
See also
LRFPattern
LRFPatternStruct
LRFPatternMode
LRFColor

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!");

Definition at line 198 of file LRF.cpp.

void LittleRobotFriend::blink ( LRFPattern  pattern,
unsigned int  duration 
)
Parameters
patternLight pattern data object
durationDuration of the pattern in milliseconds
See also
LRFPattern
LRFPatternStruct
LRFPatternMode
LRFColor

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!");

Definition at line 203 of file LRF.cpp.

void LittleRobotFriend::say ( LRFSound  sound)
Parameters
soundSound data object
See also
LRFSound
LRFSoundStruct
LRFNote
LRFOctave
LRFIntonation
LRFDuration

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!");

Definition at line 208 of file LRF.cpp.

void LittleRobotFriend::blinkAndSay ( LRFPattern  pattern,
LRFSound  sound 
)
Parameters
patternLight pattern data object
soundSound data object
See also
LRFPattern
LRFPatternStruct
LRFSound
LRFSoundStruct

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!");

Definition at line 213 of file LRF.cpp.

void LittleRobotFriend::blinkAndSay ( LRFPattern  pattern,
LRFSound sounds,
char  soundCount 
)
Parameters
patternLight pattern data object
soundsPointer to array of sound data objects
soundCountNumber of sounds in array
See also
LRFPattern
LRFPatternStruct
LRFSound
LRFSoundStruct

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!");

Definition at line 218 of file LRF.cpp.

void LittleRobotFriend::setEventHandler ( LRFEvent  event,
LRFEventHandler  handler 
)
Parameters
eventEvent type constant
handlerEvent handler function pointer
See also
LRFEvent
LRFEventHandler

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!

Definition at line 227 of file LRF.cpp.

void LittleRobotFriend::setBoredom ( unsigned int  timeout,
unsigned char  count 
)
Parameters
timeoutLength of time in seconds between yawns (lower == bores quickly)
countNumber 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)

Definition at line 310 of file LRF.cpp.

void LittleRobotFriend::sleep ( void  )

Things.

Definition at line 316 of file LRF.cpp.

LRFIRMessage LittleRobotFriend::readIRMessage ( void  )
Returns
3-bit LRFIRMessage constant

Things.

Definition at line 236 of file LRF.cpp.

void LittleRobotFriend::sendIRMessage ( LRFIRMessage  message)
Parameters
message3-bit LRFIRMessage constant

Things.

Definition at line 241 of file LRF.cpp.

unsigned char LittleRobotFriend::readTouch ( void  )
Returns
Whether or not the LRF is being touched (1 or 0)

Things.

Definition at line 250 of file LRF.cpp.

unsigned char LittleRobotFriend::readLight ( void  )
Returns
Raw value of the sensor (higher == brighter)

Things.

Definition at line 257 of file LRF.cpp.

unsigned char LittleRobotFriend::readMicrophone ( void  )
Returns
Raw value of the microphone (higher == louder)

Things.

Definition at line 264 of file LRF.cpp.

void LittleRobotFriend::setLeftLED ( unsigned char  red,
unsigned char  green,
unsigned char  blue,
bool  update = true 
)
Parameters
redRed value (max = 64)
greenGreen value (max = 64)
blueBlue value (max = 64)
updateWhether or not to update the LEDs after setting

Things.

Definition at line 275 of file LRF.cpp.

void LittleRobotFriend::setRightLED ( unsigned char  red,
unsigned char  green,
unsigned char  blue,
bool  update = true 
)
Parameters
redRed value (max = 64)
greenGreen value (max = 64)
blueBlue value (max = 64)
updateWhether or not to update the LEDs after setting

Things.

Definition at line 283 of file LRF.cpp.

void LittleRobotFriend::setBothLEDs ( unsigned char  red,
unsigned char  green,
unsigned char  blue,
bool  update = true 
)
Parameters
redRed value (max = 64)
greenGreen value (max = 64)
blueBlue value (max = 64)
updateWhether or not to update the LEDs after setting

Things.

Definition at line 291 of file LRF.cpp.


The documentation for this class was generated from the following files: