Events | LRFEvent
The Little Robot Friends Library is largely event-based. When certain states are reached, events are fired that trigger pre-defined behavior. It is possible to remap or assign these events to execute custom blocks of code.
Event Handlers
In order to reassign an event to your own code, you need to create an "event handler" this is a block of code that will be executed when an event is fired.
Create Event Handler
Example
void myTapHandler(LRFEvent event)
{
lrf.blinkAndSay(&myExpression);
}
Map Event Handler
Within the setup portion of your Arduino sketch, you need to map the particular event to your custom event handler. This is done using the setEventHandler
function, which accepts an LRFEvent
constant and the custom function we created. In this example the "Tap" event is being reassigned.
Example
void setup()
{
lrf.setup(); //setup library
// set an event handler for when we tap our hair
lrf.setEventHandler(LRFEvent_Tap, myTapHandler);
}
Event Constants
System Events
Event Name | Trigger |
---|---|
LRFEvent_RobotPowerUp |
Robot starting up. |
LRFEvent_RobotIsHungry |
Robot's battery level is low. |
LRFEvent_RobotIsBored |
Boredom timeout threshold reached. |
LRFEvent_RobotIsSleeping |
Robot enters sleep mode. |
LRFEvent_RobotIsAwake |
Robot exits sleep mode. |
LRFEvent_RobotGotMessage |
Robot received a message. |
Tap/Tickle/Hug Events
Event Name | Trigger |
---|---|
LRFEvent_Tap |
Single touch on hair sensor. |
LRFEvent_Tickle |
Multiple touches on hair sensor. |
LRFEvent_Hug |
Long touch on hair sensor. |
LRFEvent_TapLeft |
Single touch on left-hand side sensor. |
LRFEvent_TickleLeft |
Multiple touches on left-hand side sensor. |
LRFEvent_HugLeft |
Long touch on left-hand side sensor. |
LRFEvent_TapRight |
Single touch on left-hand side sensor. |
LRFEvent_TickleRight |
Multiple touches on left-hand side sensor. |
LRFEvent_HugRight |
Long touch on left-hand side sensor. |
LRFEvent_BigHug |
Long touch on both side hand sensors. |
LRFEvent_SuperHug |
Long touch on all three of the touch sensors. |
Light Events
Event Name | Trigger |
---|---|
LRFEvent_LightNormal |
Robot senses "normal" light levels. (1000 - 2500) |
LRFEvent_LightTooDark |
Robot senses decrease in light levels to dark. (Dynamic range) |
LRFEvent_LightTooBright |
Robot senses increase in light levels to bright. (Dynamic range) |
LRFEvent_LightTooDarkTooLong |
Robot senses decrease in light levels to dark for over 5 seconds. (Dynamic range) |
LRFEvent_LightTooBrightTooLong |
Robot senses increase in light levels to bright for over 5 seconds. (Dynamic range) |
Sound Events
Event Name | Trigger |
---|---|
LRFEvent_SoundNormal |
Robot returns to hearing "normal" sound levels. |
LRFEvent_SoundTooLoud |
Robot senses a loud sound like a clap or shout. |
LRFEvent_SoundLikeTalking |
Robot senses a pattern of sound that resembles talking. |
LRFEvent_SoundLikeNoTalking |
Robot no longer senses a pattern of sound that resembles talking. |
Motion Events
Event Name | Trigger |
---|---|
LRFEvent_TiltNone |
Robot is returned to standard orientation. |
LRFEvent_TiltLeft |
Robot is tilted on its left-hand side. |
LRFEvent_TiltRight |
Robot is tilted on its right-hand side. |
LRFEvent_TiltForward |
Robot is tilted on its face. |
LRFEvent_TiltBack |
Robot is tilted on its back. |
LRFEvent_LayLeft |
Robot is laying on its left-hand side. |
LRFEvent_LayRight |
Robot is laying on its right-hand side. |
LRFEvent_LayForward |
Robot is laying on its face. |
LRFEvent_LayBack |
Robot is laying on its back. |
LRFEvent_Shake |
Robot is shaken for 3 seconds. |