Little Robot Friends
Arduino Library Reference
version 1.1
|
This tutorial uses example code found in:
MyLRF04_EventHandlers.cppUp until now we’ve only been able to create expressions that play when our robot powers up, but what if we want our robot to make an expression when he’s ‘tapped’ or ‘tickled’? What about when the lights get dark or bright? For that we need to work with the LRFEvent system.
Before we get started, remember to call the LRF Library as well as include your setup()
and loop()
:
You’ll also need to create your own expression, a light pattern and sounds, for the event handler:
In order to customize events we need to create an LRFEventHandler function, which is just a regular function with no parameters (inputs) or return values (outputs). Inside that code we can put whatever we want - but most ideally that will be a custom expression:
Now the setEventHandler() function needs to be placed in the void setup function, which will include the event and the event handler function:
The setEventHandler() will override the pre-made event handler already programmed in the robot and replace it with your own event handler function. It also connects the event handler to the event you’ve chosen. In this case we’ve connected our event handler to the tap event and whenever we tap or poke the hair on the robot they will react with the customized expression. If you want to change other types of event handlers check out the LRFEvent codes and the example code listed below to find out more.
All you need to do now is upload the code. After the Little Robot Friend has powered on, tap the hair at the top and see it react with your own customized expression. Try out different event types to see how they work.