Little Robot Friends
Arduino Library Reference  version 1.1
MyLRF04_EventHandlers.cpp
1 //
2 // MyLRF04-EventHandlers.cpp
3 // LittleRobotFriends
4 //
5 // Created by Mark Argo on 2014-06-11.
6 // Copyright (c) 2014 Aesthetec Studio Inc. All rights reserved.
7 //
8 
9 /*
10  THIS SOFTWARE IS PROVIDED “AS IS”, WITHOUT ANY REPRESENTATIONS, CONDITIONS,
11  AND/OR WARRANTIES OF ANY KIND. WITHOUT LIMITATION, AESTHETEC STUDIO AND ITS
12  AFFILIATES, LICENSORS, SUPPLIERS, CONTRIBUTORS, SUBCONTRACTORS, DISTRIBUTORS
13  AND ALL CONTRIBUTORS DISCLAIM ANY EXPRESS OR IMPLIED REPRESENTATIONS,
14  CONDITIONS, OR WARRANTIES OF MERCHANTABILITY, MERCHANTABLE QUALITY, SATISFACTORY
15  QUALITY, NON-INFRINGEMENT, TITLE, DURABILITY, OR FITNESS FOR A PARTICULAR
16  PURPOSE, WHETHER ARISING BY STATUTE, COURSE OF DEALING, USAGE OF TRADE, OR
17  OTHERWISE. EXCEPT AS OTHERWISE PROVIDED IN THIS AGREEMENT, YOU SHALL BEAR
18  THE ENTIRE RISK FOR ANY USE OR ANY OTHER EXPLOITATION MADE BY YOU OF ANY
19  RIGHTS IN THE COVERED SOFTWARE.
20 
21  Additional copyright information found at http://littlerobotfriends.com/legal/
22 */
23 
24 //
25 
26 /*
27 
28  Tutorial #4 - Creating a custom event handler.
29 
30  This sketch shows you how to create a custom event handler, connect it to an
31  event, and perform an expression when that event is triggered.
32 
33  Goals:
34  - make custom patterns & sounds
35  - make a custom event handler and attach to event
36  - play around with the different event types to trigger your handler during touch, light or mic events
37 
38  */
39 
40 #include "LRF.h"
41 
42 // Create a light pattern for the eyes
43 LRFPattern myPattern = {
44  LRFColor_Blue, // starting color
45  LRFColor_Green, // target color
46  LRFPatternMode_Fade // pattern behaviour (see LRFUtils.h for more info)
47 };
48 
49 // Create an array of sounds
50 LRFSound mySounds[3] = {
53  { LRFNote_D, LRFOctave_4, LRFIntonation_Flat, LRFDuration_Long, LRFDuration_None } // <-- make sure the last entry has no comma!
54 };
55 
56 // Create a custom event handler function
57 void myTapHandler(void)
58 {
59  // let's blink and say our array of sounds
60  lrf.blinkAndSay(myPattern, mySounds, 3);
61 }
62 
63 // ------------------ everything below this point runs the program --------------------
64 
65 void setup(void) // Arduino setup routine that gets called ONCE when the robot turns on
66 {
67  lrf.setup(); // lrf library should be set up before anything else
68 
69  lrf.setEventHandler(LRFEvent_Tap, &myTapHandler); // let's connect our event handler to the tap event
70 }
71 
72 void loop(void) // Arduino loop routine that gets called OVER AND OVER while the robot runs
73 {
74  lrf.loop(); // run the lrf library
75 
76  // any other functions put in here might cause the lrf to behave strange (no delays plz!)
77 }
void loop(void)
run the LRF library loop
Definition: LRF.cpp:175
Allows for access of sound data as a structure or raw integer.
Definition: LRFUtils.h:307
This is the core API class for access LRF library functions.
Green.
Definition: LRFUtils.h:50
C (65hz)
Definition: LRFUtils.h:179
Flat tone (no change)
Definition: LRFUtils.h:219
A (55 hertz at octave #1)
Definition: LRFUtils.h:176
No duration (0 ms)
Definition: LRFUtils.h:236
Fade from start to target.
Definition: LRFUtils.h:95
void setup(void)
setup the LRF library
Definition: LRF.cpp:108
Base * 16 (whole note)
Definition: LRFUtils.h:241
void blinkAndSay(LRFPattern pattern, LRFSound sound)
Blink and speak at the same time.
Definition: LRF.cpp:213
Allows for access of pattern data as a structure or raw integer.
Definition: LRFUtils.h:156
D (73hz)
Definition: LRFUtils.h:181
void setEventHandler(LRFEvent event, LRFEventHandler handler)
Customize how your robot responds to particular events.
Definition: LRF.cpp:227
Base * 4 (1/4 note)
Definition: LRFUtils.h:239
Blue.
Definition: LRFUtils.h:51
Single touch.
middle octave
Definition: LRFUtils.h:203