Little Robot Friends
Arduino Library Reference  version 1.1
LRFUtils.h
Go to the documentation of this file.
1 //
2 // LRFUtils.h
3 // LittleRobotFriends
4 //
5 // Created by Mark Argo on 2014-05-01.
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 
31 #ifndef __LRFUtils_h
32 #define __LRFUtils_h
33 
34 #include <Arduino.h>
35 
36 //-------------------------------------------------------------
37 #pragma mark - Pattern Types
38 //-------------------------------------------------------------
39 
40 // LRFColor - lookup index for color constants (4 bits max)
44 
46 typedef enum
47 {
64 } __attribute__ ((packed)) LRFColor;
65 
69 
70 typedef struct
71 {
72  unsigned char red;
73  unsigned char green;
74  unsigned char blue;
75 } __attribute__ ((packed)) LRFColorValue;
76 
80 
90 typedef enum
91 {
106 } __attribute__ ((packed)) LRFPatternMode;
107 
111 
129 typedef struct
130 {
131  LRFColor start:4;
132  LRFColor target:4;
133  LRFPatternMode mode:4;
134  int reserved:4;
135 } __attribute__ ((packed)) LRFPatternStruct;
136 
140 
156 typedef union
157 {
158  LRFPatternStruct pattern;
159  int raw;
160 } __attribute__ ((packed)) LRFPattern;
161 
162 
163 //-------------------------------------------------------------
164 #pragma mark - Sound Types
165 //-------------------------------------------------------------
166 
170 
174 typedef enum
175 {
176  LRFNote_A = 0,
189 } __attribute__ ((packed)) LRFNote;
190 
194 
198 typedef enum
199 {
208 } __attribute__ ((packed)) LRFOctave;
209 
213 
217 typedef enum
218 {
224 } __attribute__ ((packed)) LRFIntonation;
225 
234 typedef enum
235 {
244 } __attribute__ ((packed)) LRFDuration;
245 
273 typedef struct
274 {
275  LRFNote note:4;
276  LRFOctave octave:3;
277  LRFIntonation intonation:3;
278  LRFDuration duration:3;
279  LRFDuration pause:3;
280 } __attribute__ ((packed)) LRFSoundStruct;
281 
286 #define LRFSoundStruct_Blank {LRFNote_NULL,0,0,0,0}
287 
307 typedef union
308 {
309  LRFSoundStruct sound;
310  int raw;
311 } __attribute__ ((packed)) LRFSound;
312 
313 // LRFFunctionPtr - General function pointer object
314 typedef void (*LRFFunctionPtr)(void);
315 
316 
317 //-------------------------------------------------------------
318 #pragma mark - Lookup Functions
319 //-------------------------------------------------------------
320 
333 void lrf_utils_color_lookup(LRFColor color, LRFColorValue *value);
334 
347 
360 unsigned int lrf_utils_duration_lookup(LRFDuration duration);
361 
380 unsigned int lrf_utils_note_to_frequency(LRFNote note, LRFOctave octave);
381 
382 bool lrf_utils_is_holiday_hardware(void);
383 
384 
385 #endif
D# (78hz)
Definition: LRFUtils.h:182
Falling tone (sad or upset)
Definition: LRFUtils.h:221
LRFColor
Constants for looking up color values stored in program memory (PROGMEM)
Definition: LRFUtils.h:46
LRFDuration
Constants for fixed note durations based on musical timingWe found that a short list of fixed duratio...
Definition: LRFUtils.h:234
Only use starting color with no change.
Definition: LRFUtils.h:92
LRFIntonation
Constants for speech intonation (or pitch bend)
Definition: LRFUtils.h:217
higher octave
Definition: LRFUtils.h:206
void lrf_utils_color_lookup(LRFColor color, LRFColorValue *value)
Utility for looking up LRFColorValue data from LRFColor constant.
Definition: LRFUtils.cpp:85
high octave
Definition: LRFUtils.h:205
B (62hz)
Definition: LRFUtils.h:178
Dipping tone (tone dips, then returns to normal)
Definition: LRFUtils.h:223
Allows for access of sound data as a structure or raw integer.
Definition: LRFUtils.h:307
Purple.
Definition: LRFUtils.h:54
Soft Pink.
Definition: LRFUtils.h:62
Random start and target colours with toggle effect.
Definition: LRFUtils.h:103
Base * 8 (1/2 note)
Definition: LRFUtils.h:240
LEDs off (no color)
Definition: LRFUtils.h:48
Base * 2 (1/8 note)
Definition: LRFUtils.h:238
Peaking tone (tone rises, then returns to normal)
Definition: LRFUtils.h:222
C# (69hz)
Definition: LRFUtils.h:180
Fade from start to target then back to start.
Definition: LRFUtils.h:99
A# (58hz)
Definition: LRFUtils.h:177
Use starting colour, flip start and target on reset pattern.
Definition: LRFUtils.h:93
Yellow.
Definition: LRFUtils.h:55
Random start and target colours with flat effect.
Definition: LRFUtils.h:101
Base * 1 (1/16 note)
Definition: LRFUtils.h:237
Left=starting, Right=target, fade.
Definition: LRFUtils.h:97
Pink.
Definition: LRFUtils.h:56
middle-low octave
Definition: LRFUtils.h:202
Random start and target colours with fade effect.
Definition: LRFUtils.h:102
Random start and target colours with boomerang effect.
Definition: LRFUtils.h:104
Left=starting, right=target, fade to opposite and back.
Definition: LRFUtils.h:100
Catching undefined notes.
Definition: LRFUtils.h:188
Soft Yellow.
Definition: LRFUtils.h:60
Left=starting, Right=target, fade and flip on reset.
Definition: LRFUtils.h:98
Structure for driving expressive robot sounds.
Definition: LRFUtils.h:273
Green.
Definition: LRFUtils.h:50
C (65hz)
Definition: LRFUtils.h:179
Fade from start to target, flip on reset.
Definition: LRFUtils.h:96
lowest possible octave (some notes are unplayable)
Definition: LRFUtils.h:200
Red.
Definition: LRFUtils.h:49
F (87hz)
Definition: LRFUtils.h:184
E (82hz)
Definition: LRFUtils.h:183
LRFNote
Constants for notes in the musical scale.
Definition: LRFUtils.h:174
Flat tone (no change)
Definition: LRFUtils.h:219
unsigned char blue
Blue value (8-bits)
Definition: LRFUtils.h:74
Data structure for holding RGB color values.
Definition: LRFUtils.h:70
Soft Cyan.
Definition: LRFUtils.h:61
White.
Definition: LRFUtils.h:63
G (98hz)
Definition: LRFUtils.h:186
A (55 hertz at octave #1)
Definition: LRFUtils.h:176
LRFPatternMode
Predefined pattern animations.
Definition: LRFUtils.h:90
Cyan.
Definition: LRFUtils.h:53
Left=starting color, Right=target color, flip on reset.
Definition: LRFUtils.h:94
void lrf_utils_color_lookup_random(LRFColorValue *value)
Utility for generating a random LRFColorValue.
Definition: LRFUtils.cpp:79
No pattern selected.
Definition: LRFUtils.h:105
unsigned int lrf_utils_note_to_frequency(LRFNote note, LRFOctave octave)
Utility for looking up frequency values from LRFNote and LRFOctave constants.
Definition: LRFUtils.cpp:98
No duration (0 ms)
Definition: LRFUtils.h:236
Fade from start to target.
Definition: LRFUtils.h:95
unsigned char green
Green value (8-bits)
Definition: LRFUtils.h:73
Soft Blue.
Definition: LRFUtils.h:59
F# (92hz)
Definition: LRFUtils.h:185
Base * 16 (whole note)
Definition: LRFUtils.h:241
Base * 64 (quad whole note)
Definition: LRFUtils.h:243
highest possible octave
Definition: LRFUtils.h:207
Soft Red.
Definition: LRFUtils.h:57
lower octave
Definition: LRFUtils.h:201
Orange.
Definition: LRFUtils.h:52
Soft Green.
Definition: LRFUtils.h:58
G# (104hz)
Definition: LRFUtils.h:187
Allows for access of pattern data as a structure or raw integer.
Definition: LRFUtils.h:156
D (73hz)
Definition: LRFUtils.h:181
Structure for driving LED light patterns.
Definition: LRFUtils.h:129
LRFOctave
Constants for octaves in the musical scale.
Definition: LRFUtils.h:198
Rising tone (happy or excited)
Definition: LRFUtils.h:220
unsigned int lrf_utils_duration_lookup(LRFDuration duration)
Utility for looking up duration values (in milliseconds) from a LRFDuration constant.
Definition: LRFUtils.cpp:93
unsigned char red
Red value (8-bits)
Definition: LRFUtils.h:72
Base * 4 (1/4 note)
Definition: LRFUtils.h:239
Blue.
Definition: LRFUtils.h:51
middle octave
Definition: LRFUtils.h:203
Base * 32 (double whole note)
Definition: LRFUtils.h:242
middle-high octave
Definition: LRFUtils.h:204