Little Robot Friends
Arduino Library Reference  version 1.1
LRFUtils.h File Reference

Collection of custom types and handy functions used throughout the LRF codebase. More...

#include <Arduino.h>

Go to the source code of this file.

Classes

struct  LRFColorValue
 Data structure for holding RGB color values. More...
 
struct  LRFPatternStruct
 Structure for driving LED light patterns. More...
 
union  LRFPattern
 Allows for access of pattern data as a structure or raw integer. More...
 
struct  LRFSoundStruct
 Structure for driving expressive robot sounds. More...
 
union  LRFSound
 Allows for access of sound data as a structure or raw integer. More...
 

Macros

#define LRFSoundStruct_Blank   {LRFNote_NULL,0,0,0,0}
 an empty sound (used frequenty in LRFExpressionData and LRFSignatureData)
 

Enumerations

enum  LRFColor
 Constants for looking up color values stored in program memory (PROGMEM) More...
 
enum  LRFPatternMode
 Predefined pattern animations. More...
 
enum  LRFNote
 Constants for notes in the musical scale. More...
 
enum  LRFOctave
 Constants for octaves in the musical scale. More...
 
enum  LRFIntonation
 Constants for speech intonation (or pitch bend) More...
 
enum  LRFDuration
 Constants for fixed note durations based on musical timingWe found that a short list of fixed durations covered a pretty wide range of sound timings that would be required when created new sounds. By taking this approach, we are also able to pack a lot more sound data into a smaller space - meaning more sounds for all! These constants map to a lookup table (in LRFUtils.h) that contains the actual duration values in milliseconds (as an unsigned int). More...
 

Functions

void lrf_utils_color_lookup (LRFColor color, LRFColorValue *value)
 Utility for looking up LRFColorValue data from LRFColor constant. More...
 
void lrf_utils_color_lookup_random (LRFColorValue *value)
 Utility for generating a random LRFColorValue. More...
 
unsigned int lrf_utils_duration_lookup (LRFDuration duration)
 Utility for looking up duration values (in milliseconds) from a LRFDuration constant. More...
 
unsigned int lrf_utils_note_to_frequency (LRFNote note, LRFOctave octave)
 Utility for looking up frequency values from LRFNote and LRFOctave constants. More...
 

Enumeration Type Documentation

enum LRFColor

The LRF uses 16 predefined colors for all its light patterns. These values (LRFColorValue) can be viewed in the implementation of this file (LRFUtils.cpp). These values can be changed, but be sure to update any references you might make to your new custom color, as they may affect built in patterns in the LRFExpressionData.cpp or LRFSignatureData.cpp files.

Enumerator
LRFColor_Blank 

LEDs off (no color)

LRFColor_Red 

Red.

LRFColor_Green 

Green.

LRFColor_Blue 

Blue.

LRFColor_Orange 

Orange.

LRFColor_Cyan 

Cyan.

LRFColor_Purple 

Purple.

LRFColor_Yellow 

Yellow.

LRFColor_Pink 

Pink.

LRFColor_SoftRed 

Soft Red.

LRFColor_SoftGreen 

Soft Green.

LRFColor_SoftBlue 

Soft Blue.

LRFColor_SoftYellow 

Soft Yellow.

LRFColor_SoftCyan 

Soft Cyan.

LRFColor_SoftPink 

Soft Pink.

LRFColor_White 

White.

Definition at line 46 of file LRFUtils.h.

Every pattern contains a pattern 'mode' that defines how it animates between the start and target colors (LRFColor). There are a handful of animations that cover a wide range of possibilties.

  • Flat patterns (eg: LRFPatternMode_Flat) will simply load the starting color, then do nothing.
  • Fade patterns (eg: LRFPatternMode_Fade) will load the starting color into both eyes, then fade both eyes to the target color.
  • Toggle patterns (eg: LRFPatternMode_FadeToggle) will load the starting color into the left eye and the target color into the right eye, then perform its animation.
  • Flip patterns (eg: LRFPatternMode_FadeFlip) will load the starting color, animate to the target color, and then flip 'start' and 'target' when the pattern is reset. This is handy when expressing a set of sounds and can add some complexity to your custom expression.
  • Boomerang patterns (eg: LRFPatternMode_Boomerang) fade from the starting color to the target color, then back again.
  • Random patterns (eg: LRFPatternMode_RandomFlat) choose random start and target colors for a fun surprise.

Check out the list of patterns below for a full explaination, and of course - these patterns can always be customized further!

Enumerator
LRFPatternMode_Flat 

Only use starting color with no change.

LRFPatternMode_FlatFlip 

Use starting colour, flip start and target on reset pattern.

LRFPatternMode_FlatFlipToggle 

Left=starting color, Right=target color, flip on reset.

LRFPatternMode_Fade 

Fade from start to target.

LRFPatternMode_FadeFlip 

Fade from start to target, flip on reset.

LRFPatternMode_FadeToggle 

Left=starting, Right=target, fade.

LRFPatternMode_FadeFlipToggle 

Left=starting, Right=target, fade and flip on reset.

LRFPatternMode_Boomerang 

Fade from start to target then back to start.

LRFPatternMode_BoomerangToggle 

Left=starting, right=target, fade to opposite and back.

LRFPatternMode_RandomFlat 

Random start and target colours with flat effect.

LRFPatternMode_RandomFade 

Random start and target colours with fade effect.

LRFPatternMode_RandomToggle 

Random start and target colours with toggle effect.

LRFPatternMode_RandomBoomerang 

Random start and target colours with boomerang effect.

LRFPatternMode_None 

No pattern selected.

Definition at line 90 of file LRFUtils.h.

enum LRFNote

Most sounds uttered by the LRF are pinned to the frequencies of common musical notes. These frequencies are stored in program memory (in LRFUtils.cpp) as a lookup table.

This enum is packed to 4-bits (with 13 possible values)

Enumerator
LRFNote_A 

A (55 hertz at octave #1)

LRFNote_AS 

A# (58hz)

LRFNote_B 

B (62hz)

LRFNote_C 

C (65hz)

LRFNote_CS 

C# (69hz)

LRFNote_D 

D (73hz)

LRFNote_DS 

D# (78hz)

LRFNote_E 

E (82hz)

LRFNote_F 

F (87hz)

LRFNote_FS 

F# (92hz)

LRFNote_G 

G (98hz)

LRFNote_GS 

G# (104hz)

LRFNote_NULL 

Catching undefined notes.

Definition at line 174 of file LRFUtils.h.

enum LRFOctave

The octave constants allow for shifting our stored note frequencies into higher ranges for a wider variety of sounds. Not all notes are playable for all octaves, since some of them overload the frequency timer - so it's kinda trial and error.

This enum is packed to 3-bits (with 7 possible values)

Enumerator
LRFOctave_1 

lowest possible octave (some notes are unplayable)

LRFOctave_2 

lower octave

LRFOctave_3 

middle-low octave

LRFOctave_4 

middle octave

LRFOctave_5 

middle-high octave

LRFOctave_6 

high octave

LRFOctave_7 

higher octave

LRFOctave_8 

highest possible octave

Definition at line 198 of file LRFUtils.h.

In order to make LRF sounds have extra character, the frequency of each sound can be altered over the duration of its playback. This is akin to intonation in speech. By combining a variety of notes, intonations and durations you can get some really complex expressions!

This enum is packed to 3-bits (with 5 possible values)

Enumerator
LRFIntonation_Flat 

Flat tone (no change)

LRFIntonation_Rising 

Rising tone (happy or excited)

LRFIntonation_Falling 

Falling tone (sad or upset)

LRFIntonation_Peaking 

Peaking tone (tone rises, then returns to normal)

LRFIntonation_Dipping 

Dipping tone (tone dips, then returns to normal)

Definition at line 217 of file LRFUtils.h.

This enum is packed to 3-bits (with 8 possible values)

Enumerator
LRFDuration_None 

No duration (0 ms)

LRFDuration_Short 

Base * 1 (1/16 note)

LRFDuration_DoubleShort 

Base * 2 (1/8 note)

LRFDuration_Medium 

Base * 4 (1/4 note)

LRFDuration_DoubleMedium 

Base * 8 (1/2 note)

LRFDuration_Long 

Base * 16 (whole note)

LRFDuration_DoubleLong 

Base * 32 (double whole note)

LRFDuration_VeryLong 

Base * 64 (quad whole note)

Definition at line 234 of file LRFUtils.h.

Function Documentation

void lrf_utils_color_lookup ( LRFColor  color,
LRFColorValue value 
)
Parameters
colorThe LRFColor constant to lookup
valueA pointer to a LRFColorValue variable where the value will be written

Usage:

LRFColorValue color;        // define the variable for holding the value
lrf_utils_color_lookup(LRFColor_Red, &color);   // pass the red constant AND the address to our 'color' variable
Serial.print(color.red,DEC) // print the red parameter for our color (should be 40)

Definition at line 85 of file LRFUtils.cpp.

void lrf_utils_color_lookup_random ( LRFColorValue value)
Parameters
valueA pointer to a LRFColorValue variable where the value will be written

Usage:

LRFColorValue color;        // define the variable for holding the value
lrf_utils_color_lookup_random(&color);  // pass the address to our 'color' variable
Serial.print(color.red,DEC) // print the red parameter for our color (should be ???)

Definition at line 79 of file LRFUtils.cpp.

unsigned int lrf_utils_duration_lookup ( LRFDuration  duration)
Parameters
durationThe LRFDuration constant to lookup
Returns
Duration value in milliseconds

Usage:

unsigned int duration;      // define the variable for holding the value
duration = lrf_utils_duration_lookup(LRFDuration_Medium);   // lookup the medium duration value from program memory
Serial.print(duration,DEC)  // print the medium duration in milliseconds (should be 200)

Definition at line 93 of file LRFUtils.cpp.

unsigned int lrf_utils_note_to_frequency ( LRFNote  note,
LRFOctave  octave = LRFOctave_1 
)
Parameters
noteThe musical note constant
octaveThe musical octave constant
Returns
Timer value for generating a tone at a specified frequency

Usage:

unsigned int freq;      // define the variable for holding the value
freq = lrf_utils_note_to_frequency(LRFNote_C, LRFOctave_3); // lookup the frequency value from program memory
Serial.print(freq,DEC)  // print the value

lrf_speaker_on();                   // turn on the speaker
lrf_speaker_set_frequency(freq);    // set the frequency
delay(1000);                        // delay for 1s
lrf_speaker_off();                  // turn off the speaker

Definition at line 98 of file LRFUtils.cpp.