Hello,
I play the Super Mario Bros level clear sfx on my arduino with this code:
unsigned int C6 = 1047;
unsigned int Ab5 = 831;
unsigned int Bb5 = 932;
unsigned int G5 = 784;
unsigned int F5 = 698;
unsigned int E5 = 659;
unsigned int Eb5 = 622;
unsigned int D5 = 587;
unsigned int Db5 = 554;
unsigned int C5 = 523;
unsigned int B4 = 494;
unsigned int Bb4 = 466;
unsigned int nA4 = 440;
unsigned int Ab4 = 415;
unsigned int G4 = 392;
unsigned int Gb4 = 370;
unsigned int F4 = 349;
unsigned int E4 = 330;
unsigned int Eb4 = 311;
unsigned int D4 = 294;
unsigned int Db4 = 277;
unsigned int C4 = 262;
unsigned int B3 = 247;
unsigned int Bb3 = 233;
unsigned int nA3 = 220;
unsigned int GS3 = 208;
unsigned int G3 = 196;
unsigned int Gb3 = 185;
unsigned int F3 = 175;
unsigned int E3 = 165;
#define speakerPin 11
void setup() {
pinMode(speakerPin, OUTPUT);
buzz(speakerPin,G3,166);
buzz(speakerPin,C4,166);
buzz(speakerPin,E4,166);
buzz(speakerPin,G4,166);
buzz(speakerPin,C5,166);
buzz(speakerPin,E5,166);
buzz(speakerPin,G5,500);
buzz(speakerPin,E5,500);
buzz(speakerPin,E3,166);
buzz(speakerPin,C4,166);
buzz(speakerPin,Eb4,166);
buzz(speakerPin,Ab4,166);
buzz(speakerPin,C5,166);
buzz(speakerPin,Eb5,166);
buzz(speakerPin,Ab5,500);
buzz(speakerPin,Eb5,500);
buzz(speakerPin,Bb3,166);
buzz(speakerPin,D4,166);
buzz(speakerPin,F4,166);
buzz(speakerPin,Bb4,166);
buzz(speakerPin,D5,166);
buzz(speakerPin,F5,166);
buzz(speakerPin,Bb5,500);
delay(50);
buzz(speakerPin,Bb5,166);
delay(50);
buzz(speakerPin,Bb5,166);
delay(50);
buzz(speakerPin,Bb5,166);
buzz(speakerPin,C6,2000);
}
void loop() {
// nope!
}
void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
}
However, I would like to convert it to RTTTL format. Here is an example for Super Mario World Stage Clear:
char *song = "smw_clear:d=4,o=5,b=70:8g6,8g6,16e6,8g6,16e6,16g6,16e6,16d6,8g.6,16p,32d6,16d7,16e7,16d7,16e7,16d.7,32d6,32c7,32b6,16a6,8g.6,16p,8g7";
Can someone help me do the same for Super Mario Bros Level Clear?