diff options
author | Cristian Maglie <c.maglie@bug.st> | 2013-08-08 16:43:19 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2013-08-08 16:43:19 +0200 |
commit | a8193ed933d9c9954cefbfb541cde56770ab5b74 (patch) | |
tree | 80796833fecca5d7426f1d09f7ac9870bab5f062 /libraries/Robot_Control/Melody.cpp | |
parent | a4c9fee673342304a5b12f7f2f7f9ecb9cb26d30 (diff) | |
parent | 5527c44aa443b20d63cf7a276180a36695233924 (diff) |
Merge branch 'ide-1.5.x-library-to-new-format' into ide-1.5.x
Diffstat (limited to 'libraries/Robot_Control/Melody.cpp')
-rw-r--r-- | libraries/Robot_Control/Melody.cpp | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/libraries/Robot_Control/Melody.cpp b/libraries/Robot_Control/Melody.cpp deleted file mode 100644 index 0341c55..0000000 --- a/libraries/Robot_Control/Melody.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "ArduinoRobot.h" -#include "SquawkSD.h" -#include "Fat16.h" - - - -SQUAWK_CONSTRUCT_ISR(SQUAWK_PWM_PIN5); - - -void RobotControl::beginSpeaker(uint16_t frequency){ - SquawkSynth::begin(frequency); - SquawkSynth::play(); - osc[2].vol = 0x7F; -} - -void RobotControl::playNote(byte period, word length, char modifier) { - // Modifier . makes note length 2/3 - if(modifier == '.') length = (length * 2) / 3; - // Set up the play frequency, 352800 is [sample_rate]=44100 * [tuning]=8.0 - osc[2].freq = 352800 / period; - // Delay, silence, delay - delay(length); - osc[2].freq = 0; - delay(length); -} - -void RobotControl::playMelody(char* script){ - // Find length of play string - word length = strlen(script); - // Set the default note time - word time = 500; - // Loop through each character in the play string - for(int n = 0; n < length; n++) { - // Fetch the character AFTER the current one - it may contain a modifier - char modifier = script[n + 1]; - // Fetch the current character and branch accordingly - switch(script[n]) { - // Notes - case 'c': playNote(214, time, modifier); break; // Play a C - case 'C': playNote(202, time, modifier); break; // Play a C# - case 'd': playNote(190, time, modifier); break; // Play a D - case 'D': playNote(180, time, modifier); break; // Play a D# - case 'e': playNote(170, time, modifier); break; // Play an F - case 'f': playNote(160, time, modifier); break; // Play an F - case 'F': playNote(151, time, modifier); break; // Play an F# - case 'g': playNote(143, time, modifier); break; // Play a G - case 'G': playNote(135, time, modifier); break; // Play a G# - case 'a': playNote(127, time, modifier); break; // Play an A - case 'A': playNote(120, time, modifier); break; // Play an A# - case 'b': playNote(113, time, modifier); break; // Play a B - // Delay - case '-': playNote(0, time, modifier); break; // Play a quiet note - // Note lengths - case '1': time = 1000; break; // Full note - case '2': time = 500; break; // Half note - case '4': time = 250; break; // Quarter note - case '8': time = 50; break; // Eigth note - // Modifier '.' makes note length 2/3 - - } - } -} - -void RobotControl::beep(int beep_length){ - char scr1[]="8F"; - char scr2[]="8Fe"; - char scr3[]="1F"; - - switch (beep_length) - { - case BEEP_SIMPLE: - default: - playMelody(scr1); - break; - - case BEEP_DOUBLE: - playMelody(scr2); - break; - - case BEEP_LONG: - playMelody(scr3); - } - -} - -void RobotControl::tempoWrite(int tempo){ - SquawkSynthSD::tempo(tempo); -} -void RobotControl::tuneWrite(float tune){ - SquawkSynthSD::tune(tune); -} - -void RobotControl::playFile(char* filename){ - melody.open(filename,O_READ); - SquawkSynthSD::play(melody); -} - -void RobotControl::stopPlayFile(){ - melody.close(); -}
\ No newline at end of file |