#include #define txPin 6 // Cathode end of diode #define rxPin 7 // Anode end of diode #define ledPin 13 #define SND_PLAY 0x01 #define SND_REPEAT 0x02 // Repeat count (1-254; 255 = infinite) #define SND_AGAIN 0x03 // End the repeat block. #define CHARGE 0x40 // Charge! #define TAPS 0x44 // Taps #define REVEILLE 0x5D // Reveille #define FIRSTPOST 0x7D // Horse race bugle call #define INTRO 0x8D // Doo-doot doo doot doot DOOT #define NYAH 0x93 // Nyah nyah nyah nyah NYAH nyah! #define DEAD 0x97 // Funeral dirge #define BATTHYMN 0x9D // Battle Hymn of the Republic #define DIXIE 0xA5 // Dixie #define CUCARACHA 0xAC // La Cucaracha #define POPWEASEL 0xAF // Pop! Goes the Weasel #define MARSELL 0xB3 // Marsellaise #define RULEBRIT 0xB9 // Rule Brittania #define MATILDA 0xC0 // Walzing Matilda #define KRADOUCHA 0xC6 // Kradoutcha ("There's a place in France...") #define WEDDING 0xCD // Wedding March #define ODE2JOY 0xD2 // Ode to Joy #define DUDU 0xDA // Du, Du Liegst Mir im Herzen #define NOTIME 0xE1 // Rude sound #define UHOH 0xE5 // Uh oh! #define SIREN 0xE8 // American style siren. Infinite loop: reset to exit #define PHONE 0xEE // Rings once #define WHISTLLE 0xF3 // Wolf whistle #define CRICKET 0xFA // Cricket SoftwareSerial soundPal = SoftwareSerial(rxPin, txPin); void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); playPresetNoWait(DIXIE, 1); delay(500); resetPal(); delay(1000); playPresetWait(CUCARACHA, 1); playPresetWait(DEAD, 1); playPresetNoWait(DIXIE, 1); soundPal.begin(9600); do { soundPal.print("?"); delay(2); } while(soundPal.read() != 255); soundPal.end(); Serial.println("Done"); } void loop() { } // Play preset tune; return from function without waiting for tune to end void playPresetNoWait(byte tune, byte repeats) { soundPal.begin(9600); // Open SoundPAL comm delay(10); // Brief delay soundPal.print("="); // Get attention of SoundPAL soundPal.write(byte(SND_REPEAT)); // Start repeat block soundPal.write(repeats); // Specify # to repeat soundPal.write(byte(SND_PLAY)); // Cmd to to play preset soundPal.write(tune); // Song to play soundPal.write(byte(SND_AGAIN)); // End repeat block soundPal.write(byte(0)); // Sequence end delimiter soundPal.print("!"); // Play sequence in RAM soundPal.end(); // Close SoundPal comm } // Play preset tune; return from function after tune ends void playPresetWait(byte tune, byte repeats) { digitalWrite(ledPin, HIGH); soundPal.begin(9600); delay(10); soundPal.print("="); soundPal.write(byte(SND_REPEAT)); soundPal.write(repeats); soundPal.write(byte(SND_PLAY)); soundPal.write(tune); soundPal.write(byte(SND_AGAIN)); soundPal.write(byte(0)); soundPal.print("!"); delay(10); do { soundPal.print("?"); delay(2); } while(soundPal.read() != 255); Serial.println("Done"); soundPal.end(); digitalWrite(ledPin, LOW); } // Reset SoundPAL (stop all sound) void resetPal() { soundPal.begin(1200); // Send minimum 7.5ms LOW pulse to reset soundPal.write(byte(0)); soundPal.end(); }