Here is what I came up with! Please like on YouTube! Let me know if you see any room for improvement in the code. Thanks!
Code Used:
/*
Melody
Plays a melody
circuit:
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
modified by Evan Johnson Jan 2013 "Taps" melody and 3 fading leds.
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
// notes in the melody:
int melody[] = {NOTE_G4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4,
NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5,
NOTE_E5, NOTE_C5, NOTE_E5, NOTE_G5, NOTE_E5, NOTE_C5, NOTE_G4,
NOTE_G4, NOTE_G4, NOTE_C5};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {2,4,1, 2,4,1, 4,4,2, 4,4,2, 4,4,1, 2,4,1, 2,2,1, 2,4,1};
int redLedPin = 3; // red LED connected to digital pin 3
int whiteLedPin = 5; // white LED connected to digital pin 5
int blueLedPin = 6; // blue LED connected to digital pin 6
void setup() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
{
// sets the value (range from 0 to 255):
analogWrite(redLedPin, fadeValue);
analogWrite(whiteLedPin, fadeValue);
analogWrite(blueLedPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(40);
}
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 24; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 2500/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.05;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
{
// sets the value (range from 0 to 255):
analogWrite(redLedPin, fadeValue);
analogWrite(whiteLedPin, fadeValue);
analogWrite(blueLedPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(40);
}
}
void loop()
{
}