Little Robot Friends
Arduino Library Reference  version 1.1
MyLRF05_MoreEventHandlers.cpp
1 //
2 // MyLRF05-MoreEventHandlers.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 #5 - Using multiple custom event handlers.
29 
30  This sketch shows you how to create multiple custom event handlers, connect them to
31  events, and perform expressions when those events are triggered.
32 
33  Goals:
34  - make custom patterns & sounds
35  - make a couple custom event handlers and attach to events
36  - play around with the different event types to create a unique set of responses to a touch or light 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 another light pattern for our second handler
50 LRFPattern myOtherPattern = {
51  LRFColor_Pink, // starting color
52  LRFColor_Purple, // target color
53  LRFPatternMode_BoomerangToggle // pattern behaviour (see LRFUtils.h for more info)
54 };
55 
56 // Create an array of sounds
57 LRFSound mySounds[3] = {
60  { LRFNote_D, LRFOctave_4, LRFIntonation_Flat, LRFDuration_Long, LRFDuration_None } // <-- make sure the last entry has no comma!
61 };
62 
63 // Create a custom event handler function
64 void myTapHandler(void)
65 {
66  // let's blink and say our array of sounds
67  lrf.blinkAndSay(myPattern, mySounds, 3);
68 }
69 
70 void myTickleHandler(void)
71 {
72  // let's blink our other pattern with our sounds
73  lrf.blinkAndSay(myOtherPattern, mySounds, 3);
74 }
75 
76 // ------------------ everything below this point runs the program --------------------
77 
78 void setup(void) // Arduino setup routine that gets called ONCE when the robot turns on
79 {
80  lrf.setup(); // lrf library should be set up before anything else
81 
82  // let's connect our event handlers
83  lrf.setEventHandler(LRFEvent_Tap, &myTapHandler);
84  lrf.setEventHandler(LRFEvent_Tickle, &myTickleHandler);
85 }
86 
87 // Arduino loop routine that gets called OVER AND OVER while the robot runs
88 void loop(void)
89 {
90  // run the lrf library
91  lrf.loop();
92 
93  // any other functions put in here might cause the lrf to behave strange (no delays plz!)
94 }
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
Purple.
Definition: LRFUtils.h:54
This is the core API class for access LRF library functions.
Pink.
Definition: LRFUtils.h:56
Left=starting, right=target, fade to opposite and back.
Definition: LRFUtils.h:100
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
Multiple touch.
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