Created
December 14, 2014 19:16
-
-
Save mhermans/b5c39250ce74c8974324 to your computer and use it in GitHub Desktop.
Arduino "You are my sunshine" version using toneAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <toneAC.h> | |
#define c 261.626 // 261 Hz | |
#define d 293.665 // 294 Hz | |
#define e 329.628 // 329 Hz | |
#define f 349.228 // 349 Hz | |
#define g 391.995 // 392 Hz | |
#define a 440.000 // 440 Hz | |
#define b 493.883 // 493 Hz | |
#define C 523.251 // 523 Hz | |
#define R 0 | |
/* | |
(notes above words) | |
g-----c----d----e----e | |
you are my sunshine | |
e-----d-e---c----c | |
my only sunshine | |
c-----d-------e-----f---a | |
you make me happy | |
a--------g------f-----e | |
when skies are grey | |
c-------d---e---f-------a | |
you'll never know dear | |
a-----g-------f---e---c | |
how much I love you | |
g---c---------d------e-----f | |
so please don't take my | |
d----d-------e---c | |
sunshine away | |
*/ | |
int melody[] = { g, c, d, e, e, R, | |
e, d, e, c, c, R, | |
c, d, e, f, a, R, | |
a, g, f, e, R, | |
c, d, e, f, a, R, | |
a, g, f, e, c, R, | |
g, c, d, e, f, R, | |
d, d, e, c, R | |
}; | |
int noteDurations[] = { 4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 8, | |
4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 4, 8, | |
4, 4, 4, 4, 8 | |
}; | |
void setup() {} // Nothing to setup, just start playing! | |
void loop() { | |
for (int thisNote = 0; thisNote < 47; thisNote++) { | |
int noteDuration = 1000/noteDurations[thisNote]; | |
toneAC(melody[thisNote], 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the background. | |
delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay between notes. | |
} | |
while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome). | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment