Hello fellow Arduino users,
I have a code that plays the Popcorn song, feel free to use it or change it for yourself:
#include "pitches.h"
//The Pin for 8ohm speaker is 8....
int melody[] = {
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5, 0,
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5, 0,
NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_D6, NOTE_DS6, NOTE_C6, NOTE_D6, NOTE_C6,
NOTE_D6, NOTE_AS5, NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_C6, 0,
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5, 0,
NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_DS5, NOTE_G5, NOTE_C5, 0,
NOTE_C6, NOTE_D6, NOTE_DS6, NOTE_D6, NOTE_DS6, NOTE_C6, NOTE_D6, NOTE_C6,
NOTE_D6, NOTE_AS5, NOTE_C6, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_C6,
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4
};
void setup() {
for (int thisNote = 0; thisNote < 64; thisNote++) {
int noteDuration = 900/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1;
delay(pauseBetweenNotes);
noTone(8);
}
}
void loop() {
}
I want to make the LEDs blink in rhythm with the beeps of my tiny Arduino "player"
I have an Arduino Mega 2560 R3
What can I add to my code to make one or more LEDs blink in rhythm with the music?