On Arduino software on your computer, open a new document (or sketch) from the “File” menu. Replace all the existing code within the new document by copying and pasting code (from “//start code” to line “//end code”  into the document. Then go to “File” menu, select “Save” to save the document with file name “Musical Elf Ornament Kit”.

Make sure that you replace any existing code within the new document and copy & paste only the code portion of this post. After you save the document, click on the verify button to see if the program compiles ok.  If not, please repeat the process as described.

//start code
/*
* Arduino code for Musical Elf Kit with LED By KiteCoders
*
* Uses a DigiSpark ATTiny85 USB micro-controller module to produce simple musical notes
* For a chart of the frequencies of different notes see:
* http://www.phy.mtu.edu/~suits/notefreqs.html
*/

//decalre variables and pin assignments
int speakerPin = 0; // speaker connected to digital pin 0 on Digispark pin #0
#define gnd1 1 //assigning the pin #1 as ground for the speaker

int ledPin = 2; // LED is connected to digital pin 2
#define gnd2 3 //assigning the pin #1 as ground for the LED
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output
pinMode(gnd1, OUTPUT);
digitalWrite (gnd1, LOW); // use this pin as a ground
pinMode(gnd2, OUTPUT);
digitalWrite (gnd2, LOW); // use this pin as a ground
}

void loop() // run over and over again
{
scale(); // call the scale() function
delay(1000); // delay for 1 second
}

void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // the sound producing function
{
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x<loopTime;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
}

void scale ()
{
digitalWrite(ledPin,HIGH); //turn on the LED on
beep(speakerPin,329,250); //play the note Middle E (E4 from the chart linked to above for 250 millisec duration)
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH); //turn the LED off, wait for 20 ms and then turn it back on
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,500);
digitalWrite(ledPin,LOW); delay(100); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,500);
digitalWrite(ledPin,LOW); delay(100); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,392,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,262,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,294,125);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,1000);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,349,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,349,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,349,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,349,250);
digitalWrite(ledPin,LOW); delay(100); digitalWrite(ledPin,HIGH);
beep(speakerPin,349,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,500);
digitalWrite(ledPin,LOW); delay(100); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,294,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,294,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,329,250);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,294,500);
digitalWrite(ledPin,LOW); delay(20); digitalWrite(ledPin,HIGH);
beep(speakerPin,392,500);
delay(1000);
digitalWrite(ledPin,LOW); //turn off the LED
}
//end code