Create your Christmas tree

Christmas Tree

This example shows you how to realize a sonorous Christmas tree commanded by an Arduino board. 
In particular in this project is used an Arduino Mini 05, for its small dimensions but it is possible to use another Arduino board, powered via an external 9V battery.

Arduino Mini 05  

Also it is used a buzzer to play the Christmas songs connected to a potentiometer to adjust the volume level of music.

Buzzer  

Hardware

  • Arduino Mini 05 (or another Arduino board)
  • 16 colored LEDs (4 Yellow, 4 Red, 4 Blue and 4 Green)
  • A bunch of wires
  • 1 buzzer
  • 1 potentiometer from 10 KOHM
  • 1 external 9V battery

Circuit

Follow these steps to realize the project: 
- Print using a 3D printer the Christmas tree from this link: 
http://www.thingiverse.com/thing:34197/#files

3D  printer    

Christmas Tree  

Or create your tree as you prefer. 
- Connect the positive pole of Buzzer to pin D13 of board and the negative to the GND. 
- Insert the potentiometer connecting the central pin to pin D13, and the other two pins respectively to 5V and GND of board. 
- Connect together the anodes(usually the longer pin) of the LEDs of the same color and connect them to the digital pins between D3 and D6.(For example all Red Leds to pin 3, the Yellow Leds to pin 4, the Blue Leds to pin 5 and the Green Leds to pin 6) 
Instead connect the cathodes of the LEDs to GND of board. 
- Place the Leds on Christmas tree. 
- If you want power the board with an external power then you can connect the positive terminal of a 9V battery to 9V pin of board and the negative terminal to GND, also you can use a switch to turn on/off.

Project in progress  

- If you have an Arduino Mini you need to use an Arduino USB 2 Serial micro to programm the board. 
http://www.arduino.org/products/accessories/7-arduino-accessories/arduino-usb-2-serial-micro 
- Plug in the board to the Arduino USB 2 Serial micro and connect it to PC. 
Now the circuit is ready.

Arduino  Christmas Tree  

Upload the sketch!

Code

The sketch uses the Tone.h library, you can downlod it here
You can select untill five songs between a list of 30. 
The notes of the songs are availables from this website: http://www.mauroalfieri.it/elettronica/suonerie-natalizie-arduino.html 
During the songs the Leds turn on according of music.

The complete code and its detailed description are shown down.

 
 
//inclde library
#include <Tone.h>
Tone tone1;
byte contatore = 0;
#define OCTAVE_OFFSET 0
//Notes
int notes[] = { 0, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7
};
 
/*Christmas songs: select your favorites songs*/
 
//char *song0 = "XMASHEARTS:d=4,o=5,b=70:16a4,8a.,16a#,8a,8g,8f,8g,8a,16g,16a,8a#,8a,8g,8f,e,8p,16e,16f,g,8g.,16a,g,8p,16a,16a#,8a,8g,8f,8g,a,8p,16a4,8a,8a,8a.,16f,8a#,8a,8p,16g#,16a,8d6,8d6,8a,8c6,a#,8p,16g,16a,a#.,8c6,8a#,8a,8p,8e,8a,8g,8f,8e,d,8p,8d,8c,8e,8f,8g,a,8p,16e,16f,g.,8c,8a#,a,8d,8c,8e,8f,8g,a,8p,8a,8g#,8a,2b,c6,2c.6";
//char *song1 ="firstnoel:d=4,o=5,b=112:16e.,32p,8d,c.,8d,8e,16f.,32p,g.,8p,16a,16p,16b.,32p,c6,b,8a.,16p,g.,8p,16a.,32p,16b.,32p,c6,b,a,g,8a.,16p,b,c6,g,f,e.";
//char *song2 ="firstnoel2:d=16,o=5,b=28:32f#,32e,d.,32e,32f#,32g,a.,32p,32b,32c#6,d6,c#6,b,a.,32p,32b,32c#6,d6,c#6,b,a,b,c#6,32d6,a,g,f#.,32p,32f#,32e,d.,32e,32f#,32g,a.,32p,32d6,32c#6,b.,32p,b,8a,p,d6,c#6,b,a,b,c#6,d6,a,g,f#.,32p,32f#,32e,d.,32e,32f#,32g,a.,32p,32b,32c#6,d6,c#6,b,a.,32p,32b,32c#6,32d6,c#6,b,a,b,c#6,d6,a";
//char *song3 ="Angels_on_high:d=4,o=5,b=180:a,a,a,c6,c.6,8a#,2a,a,g,a,c6,a.,8g,2f,a,a,a,c6,c.6,8a#,2a,a,g,a,c6,a.,8g,2f,2c6,8d6,8c6,8a#,8a,2a#,8c6,8a#,8a,8g,2a,8a#,8a,8g,8f,g.,8c,2c,f,g,a,a#,2a,2g,1f";
//char *song4 ="All I Want For Christmas:d=4,o=5,b=100:c,e,g,b,a,2a,8g,8e,c,e,g,b,a,2d,a,b4,d,f,b,a,2a,8d,8e,f,g,a,b,1g,c,e,g,b,a,2a,8g,8e,c,e,g,b,a,2d,a,b4,d,f,b,a,2a,8d,8e,f,g,a,b,c6,g,c6,c6,d6,a,a,8b,8d6,c6,g,2g,b,a,g,f,2e.,e,a,e,e,8f#,8a,g,d,2d,f#,e,d,c";
//char *song5 ="In the Bleak MidWinter:d=4,o=5,b=112:b.,8c6,d6,b,2a,2g,a.,8b,a,e,2a.,p,b.,8c6,d6,b,2a,2g,a.,8b,a.,8g,2g.,p,c6,b,c6,d6,e6,e6,2b,d.6,8b,a.,8g,2a.,p,b.,8c6,d6,b,2a,2g,a.,8b,a.,8g,2g.";
//char *song6 ="Jingle Bells 2:d=4,o=5,b=225:b4,g#,f#,e,2b.4,c,c#,a,g#,f#,2c#,p,8c#,8p,c#,a,g#,f#,2b.,g#,f#,c#,d#,8e.,32p,2f#,p,8b4,8p,b4,g#,f#,e,2b.4,c,c#,a,g#,f#,2c#,p,8c#,8p,c#,a,g#,f#,b,g#,8e.,g#,8f#,8p,f#,g#,a#,2b,2p,b4,g#,f#,e,2b.4,c,c#,a,g#,f#,2c#,p,8c#,8p,8c#.,32p,a,g#,f#,2b.,g#,f#,c#,d#,e,2f#,p,8b4,8p,b4,g#,f#,e,2b.4";
char *song7 ="Jingle Rock Rock:d=8,o=5,b=160:32c6,p,c6,c6,p,16b,16p.,b,b,p,a,32p,b,a,p,e,4p.,a,32p,b,a,16p.,e,p,g,p,a,32p,b,a,p,f,4p.,d,32p,e,f,p,g,p,a,p,d,32p,e,f,p,g,p,16a,16p,a,a,16p,b,p,g,c6";
//char *song8 ="Jolly Old St Nicholas:d=8,o=5,b=112:d6,d6,d6,d6,c6,c6,4c6,a#,a#,a#,a#,2d6,g,g,g,g,f,f,4a#,a,a#,c6,d6,2c6,d6,d6,d6,d6,c6,c6,4c6,a#,a#,a#,a#,2d6,g,g,g,g,f,f,4a#,c6,a#,c6,d6,4a#";
//char *song9 ="Joy to the World:d=8,o=5,b=56:4c6,b.,16a,4g.,f,4e,d.,16p,4c.,g,4a.,a,4b.,b,2c.6,p,c6,c6,b,a,g,g.,16f,e,c6,c6,b,a,g,g.,16f,e,e,e,e,e,16e,16f,4g.,16f,16e,d,d,d,16d,16e,4f.,16e,16d,c,4c6,a,g.,16f,e,f,4e,4d,2c";
//char *song10="Let it Snow:d=4,o=5,b=125:8c,8c,8c6,8c6,a#,a,g,f,2c,8c,16c,g.,8f,g.,8f,e,2c,d,8d6,8d6,c6,a#,a,2g.,8e.6,16d6,c6,8c.6,16a#,a,8a#.,16a,2f.,c,8c6,8c6,a#,a,g,f,2c,8c.,16c,g.,8f,g.,8f,e,2c,d,8d6,8d6,c6,a#,a,2g.,8e.6,16d6,c6,8c.6,16a#,a,8a.,16g,2f.";
char *song11="Rudolph The Red Nose Reindeer:d=4,o=5,b=250:8g,a,8g,e,c6,a,2g.,8g,8a,8g,8a,g,c6,2b.,p,8f,g,8f,d,b,a,2g.,8g,8a,8g,8a,g,a,2e.,p,8g,a,8a,e,c6,a,2g.,8g,8a,8g,8a,g,c6,2b.,p,8f,g,8f,d,b,a,2g.,8g,8a,8g,8a,g,d6,2c.6,p,a,a,c6,a,g,e,2g,d,e,g,a,b,b,2b,c6,c6,b,a,g,f,2d,8g,a,8g,e,c6,a,2g.,8g,8a,8g,8a,g,c6,2b.,p,8f,g,8f,d,b,a,2g.,g,a,g,a,";
//char *song12="Santa Claus is Coming to Town:d=4,o=5,b=200:g,8e,8f,g,g.,8g,8a,8b,c6,2c6,8e,8f,g,g,g,8a,8g,f,2f,e,g,c,e,d,2f,b4,1c,p,g,8e,8f,g,g.,8g,8a,8b,c6,2c6,8e,8f,g,g,g,8a,8g,f,f,e,g,c,e,d,2f,b4,1c,p,c6,d6,c6,b,c6,a,2a,c6,d6,c6,b,c6,2a.,d6,e6,d6,c#6,d6,b,b,b,8b,8c6,d6,c6,b,a,g,p,g.,8g,8e,8f,g,g.,8g,8a,8b,c6,2c6,8e,8f,g,g,g,8a,8g,8f,2f,";
//char *song13="Sleigh Ride:d=8,o=5,b=225:b,p,b,p,b,p,b,p,c#6,p,b,16g#,4e,f#,p,g#,p,f#,16d#,4c#,1b4,4p,c#,16p.,d#,p,f#,p,b,p,c#6,p,b,g#,f#,e,f#,p,f#,g#,f#,e,4c#,1e,4p,b,p,b,p,b,p,b,p,c#6,p,b,16g#,4e,f#,p,g#,p,f#,16d#,4c#,1b4,4p,c#,p,d#,p,f#,16p.,b,p,c#6,p,b,g#,f#,e,f#,p,f#,g#,f#,e,4c#,1e,4p,b,p,b,p,b,p,b,p,c#6,p,b,16g#,4e,";
char *song14="The First Noel:d=16,o=5,b=28:32f#,32e,d.,32e,32f#,32g,a.,32p,32b,32c#6,d6,c#6,b,a.,32p,32b,32c#6,d6,c#6,b,a,b,c#6,32d6,a,g,f#.,32p,32f#,32e,d.,32e,32f#,32g,a.,32p,32d6,32c#6,b.,32p,b,8a,p,d6,c#6,b,a,b,c#6,d6,a,g,f#.,32p,32f#,32e,d.,32e,32f#,32g,a.,32p,32b,32c#6,d6,c#6,b,a.,32p,32b,32c#6,32d6,c#6,b,a,b,c#6,d6,a";
//char *song15="Twelve Days of Christmas:d=16,o=5,b=90:c.,c.,8c.,f.,f.,8f.,e.,f.,g.,a.,a#.,g.,4a,32p,a#.,8c.6,d.6,a#.,a.,f.,8g.,2f,c.,c.,c.,f.,f.,f.,8f.,e.,f.,g.,a.,a#.,g.,4a.,8c.6,g.,a.,8a#.,a.,a#.,8c.6,d.6,a#.,a.,f.,8g.,4f.";
//char *song16="12 Days OF Christmas:d=4,o=5,b=140:8d,8d,d,8g,8g,g,8f#,8g,8a,8b,8c6,8a,b,8p,8c6,d6,8e6,8c6,8b,8g,a,2g,8d6,8d6,d6,8g6,8g6,g6,8f#6,8g6,8a6,8b6,8c7,8a6,2b6,d7,8a,8b,c6,8b6,8c7,d7,8e7,8c7,8b6,8g6,a6,2g.6,8f#,8f#,f#,8b,8b,b";
//char *song17="CarolBells:d=8,o=5,b=180:4a,g#,a,4f#,4a,g#,a,4f#,4f#6,f#6,f#6,e6,d6,4c#6,c#6,c#6,b,a,4b,b,b,c#6,b,4f#,f#,f#,4f#,c#,d#,e,f#,g#,a,b,c#6,4b,4a,c#,d#,e,f#,g#,a,b,c#6,4b,4a,4a,g#,a,4f#,4a,g#,a,4f#";
//char *song18="Away In A Manger:d=4,o=5,b=112:d6,d.6,8c6,b,b.,8a,g,g,f#,e,2d,d,d.,8e,d,d,a,f#,e,d,g,2b,d6,d.6,8c6,b,b.,8a,g,g,f#,e,2d,d,c.6,8b,a,b,a,g,a,e,f#,2g,d6,d.6,8c6,b,b.,8a,g,g,f#,e,2d,d,d.,8e,d,d,a,f#,e,d,g,2b";
//char *song19="Ill be home for Xmas:d=8,o=6,b=40:c.7,16b,d.7,16c7,g,4g,p,a.,16g,a#.,16a,4d,p,d.,16e,g.,16f,e.,16g,c.7,16b,d7,d7,b,32p,16b,4a,g,p,c.7,c.7,16b,d.7,16c7,g,4g,p,a.,16g,a#.,16a,4d,p,d.,16e,g.,16f,e.,16g,c.7,16b,d7,d7,b.,16b,4a,g,p,c.7,c.7,16b,d.7,16c7,g,4g,p,a.,16g,a#.,16a,4d,p,d,32p,16e,g.,16f,e.,16g,c.7,16b,d7,d7,b.,";
//char *song20="Deck The Halls:d=4,o=5,b=160:c.6,8a#,a,g,f,g,a,f,8g,8a,8a#,8g,a.,8g,f,e,2f,c.6,8a#,a,g,f,g,a,f,8g,8a,8a#,8g,a.,8g,f,e,2f,g.,8a,a#,g,a.,8a#,c6,g,8a,8b,c6,8d6,8e6,f6,e6,d6,2c6,c.6,8a#,a,g,f,g,a,f,8d6,8d6,8d6,8d6,c.6,8a#,a,g,2f";
//char *song21="I Saw Mommy Kissing Santa Claus:d=4,o=6,b=160:2c.,d,e,g,a,8c7,2b.,g,2e,a,g,e,c,a,g,e,8c.,2b.5,f,e,d,d.,8c#.,2d.,8a.,16b.,8a.,g.,f#.,8a.,2g.,e,d,e,f#,g,a,g#,a,a#,b,a,f,8e,2d.,g,2c.,d,e,g,a,8c7,2b,g,2e,a,g,2e,16c,a,g,e,8c.,2a,16g#,8a.,16b,c7,8c.7,c7,8d.7,1b,f#,8a.,16a,g,f,8e,2d,8e.,2f,g,a,8c.7,a,2c7,2d7,1c7";
char *song22="Feliz Navidad:d=4,o=5,b=140:8a,d6,8c#6,8d6,2b.,p,8b,e6,8d6,8b,2a.,p,8a,d6,8c#6,8d6,b.,8g,b,b,8a,8a,8b,8a,g,8g,1f#,p,8a,d6,8c#6,8d6,2b.,p,8b,e6,8d6,8b,2a.,p,8a,d6,8c#6,8d6,b.,8g,b,b,8a,8a,8b,8a,g,8g,1f#,p,8f#6,8f#6,8f#6,8f#6,e6,8d6,d6,b,8b,d.6,8p,8e6,8e6,8e6,e6,8d6,8b,b,a,8g#,a.";
//char *song23="Frosty The Snowman:d=4,o=5,b=140:2g,e,8p,8f,g,2c6,8b,8c6,d6,c6,b,a,2g,p,8b,8c6,d6,c6,b,8a,8a,8g,c6,e.,8f,8a,g,f,e,f,2g,2p,2g,e,8p,8f,g,2c6,8b,8c6,d6,c6,b,a,2g,p,8b,8c6,d6,c6,b,8a,8a,8g,c6,e.,8g,8a,g,f,e,d,2c,p,c,a,a,c6,c6,b,a,g,e,f,a,g,f,2e,p,e,d,d,g,g,b,b,d6,8d6,8b,d6,c6,b,a,g,p,2g";
//char *song24="Have Yourself A Merry Little Christmas:d=4,o=5,b=100:16b4,8c,8e.,g.,16b,8c6,8g,f,16p,8e,16d,c,16c,d.,8p,16b4,8c,8e,g.,16b,8c.6,2g,p,e,g,c6,16d6,8e.6,8d.6,8c6,8b,8a,g,16e,f,2e,16p,8f,16g,16d,16d,8c,8d,16a4,c.,e,g,16b,8c.6,8g,f.,16p,8e,16d,8c,16d,16e,8d.,8e,8p,16c,8e,g.,16b,8c6,2g,p,e,g,c6,d6,8d.6,16c6,16p,8b,16a,g#.,8b.,16b,2c.6,16p";
//char *song25="Last Christmas:d=4,o=5,b=112:16d6,e6,8p,e6,8d6,8p,8a,8e6,8e6,8f#6,d.6,8b,8b,8e6,8e6,f#6,d.6,8b,8c#6,8d6,8c#6,2b.,16e6,f#6,8p,e.6,8p,8b,8f#6,8g6,8f#6,2e6,8d6,8c#6,8d6,8c#6,c#6,8d6,8p,8c#6,8p,2a,16d6,e6,8p,e6,8d6,8p,8a,8e6,8e6,8f#6,d.6,8b,8b,8e6,8e6,f#6,d.6,8b,8c#6,8d6,8c#6,2b.,16e6,f#6,8p,e.6,8p,8b,8f#6,8g6,8f#6,2e6,8d6,8c#6,8d6,8c#6,c#6,8d6,8p,8c#6,8p,a";
//char *song26="chestnuts Roasting On An Open Fire:d=4,o=5,b=125:8d#,16p,16d6,8d#6,16c#6,8d.6,8c6,a#,8g#,8p,16f,8g.,8a#,a#,16a#,8c.6,2d#,p,8d#,16p,16a#,8c6,a#,8g#,16f,8g.,8a#,16d#,16f,1d#,p,8c,16d,16d#,8d,8d#,f.,p,8d,8d#,8f,8f,g,8a#,8p,8c6,8g,16c6,1d6,8c6,8b,8c6,d.6,8b,16p,16b,c#6,8b,8p,a#,8g#,8p,16g#,1a#,p,p";
char *song27="we Wish You A Merry Christmas:d=4,o=5,b=200:d,g,8g,8a,8g,8f#,e,e,e,a,8a,8b,8a,8g,f#,d,d,b,8b,8c6,8b,8a,g,e,d,e,a,f#,2g,d,g,8g,8a,8g,8f#,e,e,e,a,8a,8b,8a,8g,f#,d,d,b,8b,8c6,8b,8a,g,e,d,e,a,f#,1g,d,g,g,g,2f#,f#,g,f#,e,2d,a,b,8a,8a,8g,8g,d6,d,d,e,a,f#,2g";
//char *song28="Winter Wonderland:d=4,o=5,b=112:8a#.,16a#,2a#.,8a#.,16a#,g,2a#,8a#.,16a#,2a#.,8a#.,16a#,g#,2a#,8p,16a#,8d.6,16d6,8d.6,c.6,8p,16c6,8a#.,16a#,8a#.,g#.,8p,16g#,8g.,16g,8g.,16g,8f.,16f,8f.,16f,2d#,p,8a#.,16a#,2a#.,8a#.,16a#,g,2a#,8a#.,16a#,2a#.,8a#.,16a#,g#,2a#,8p,16a#,8d.6,16d6,8d.6,c.6,8p,16c6,8a#.,16a#,8a#.,g#.,8p,16g#,8g.,16g,8g.,16g,8f.,16f,8f.,16f,2d#,p,8d.,16d,8b.,16b,8e.,16e,8c.6,16c6,b,2g,p,8d.,16d,8b.,16b,8e.,16e,8c.6,16c6,2b.,p";
//char *song29="Mary's boy child - Bony M:d=16,o=6,b=40:32g,32p,g,g,c7,c7,a,f,d,32a,32a,g,b,a,f,4e,g,e7,d7,c7,a,f,d.,g,c7,b,d7,4c7,e7,e7,f7,f7,d7,d7,e.7,32e7,c7,c7,d7,c7,8b.,a,g,e7,d7,c7,a,f,d.,32a,g,c7,b,d7,4c7,32g,32p,g,g,c7,c7,a,f,d,32a,32a,g,b,a,f,8e.,32p,g,e7,d7,c7,a,f,d.,32a,g,c7,b,d7,4c7,e7,e7,f7,f7,d7,d7,e.7,32e7,c7,c7,d7,c7,8b";
//char *song30="cristmas In Our Hearts:d=4,o=5,b=70:16a4,8a.,16a#,8a,8g,8f,8g,8a,16g,16a,8a#,8a,8g,8f,e,8p,16e,16f,g,8g.,16a,g,8p,16a,16a#,8a,8g,8f,8g,a,8p,16a4,8a,8a,8a.,16f,8a#,8a,8p,16g#,16a,8d6,8d6,8a,8c6,a#,8p,16g,16a,a#.,8c6,8a#,8a,8p,8e,8a,8g,8f,8e,d,8p,8d,8c,8e,8f,8g,a,8p,16e,16f,g.,8c,8a#,a,8d,8c,8e,8f,8g,a,8p,8a,8g#,8a,2b,c6,2c.6";
 
// array below shows the initial ON/OFF status of the LEDs:
int LEDs[] = {1, 1, 1, 1,         1, 0, 1, 0, 1, 0, 1, 0, 1, 0};        
//array songs
char *songs[5];    
/*setup*/
void setup(void) {
tone1.begin(13);//initialize tone
//indicate the number of your favorites songs
songs[0] = song7;
songs[1] = song22;
songs[2] = song11;
songs[3] = song27;
songs[4] = song14;
int i;
//define the Leds as Output
  for (i = 3; i <= 6; i++) {
  pinMode(i, OUTPUT);
  }
}
/*loop*/
void loop(void) {
if (contatore < 0 || contatore > 5 ) contatore = 0;
play_rtttl(songs[contatore]);
delay(1000);
contatore++;
}
/*Function to play songs*/
void play_rtttl(char *p) {
 
byte default_dur = 4;
byte default_oct = 6;
int bpm = 63;
int num;
long wholenote;
long duration;
byte note;
byte scale;
// format: d=N,o=N,b=NNN:
// find the start (skip name, etc)
while(*p != ':') p++;   // ignore name
p++;                     // skip ':'
// get default duration
if(*p == 'd') {
  p++; p++;             // skip "d="
  num = 0;
  while(isdigit(*p)) {
    num = (num * 10) + (*p++ - '0');
  }
  if(num > 0) default_dur = num;
  p++;                   // skip comma
// get default octave
if(*p == 'o') {
  p++; p++;             // skip "o="
  num = *p++ - '0';
  if(num >= 3 && num <=7) default_oct = num;
  p++;                   // skip comma
}
// get BPM
if(*p == 'b') {
  p++; p++;             // skip "b="
  num = 0;
  while(isdigit(*p)) {
    num = (num * 10) + (*p++ - '0');
  }
  bpm = num;
  p++;                   // skip colon
}
// BPM usually expresses the number of quarter notes per minute
wholenote = (60 * 1000L / bpm) * 4; // this is the time
                                      // for whole note (in milliseconds)
// now begin note loop
while(*p) {
  // first, get note duration, if available
  num = 0;
  while(isdigit(*p)) {
    num = (num * 10) + (*p++ - '0');
  }    
  if(num) duration = wholenote / num;
  else duration = wholenote / default_dur; // we will need to check
                                            // if we are a dotted note after
  // now get the note
  note = 0;
  switch(*p) {
    case 'c':
      note = 1;
      break;
    case 'd':
      note = 3;
      break;
    case 'e':
      note = 5;
      break;
    case 'f':
      note = 6;
      break;
    case 'g':
      note = 8;
      break;
    case 'a':
      note = 10;
      break;
    case 'b':
      note = 12;
      break;
    case 'p':
    default:
      note = 0;
  }
  p++;
  // now, get optional '#' sharp
  if(*p == '#') {
    note++;
    p++;
  }
  // now, get optional '.' dotted note
  if(*p == '.') {
    duration += duration/2;
    p++;
  }
  // now, get scale
  if(isdigit(*p)) {
    scale = *p - '0';
    p++;
  } else {
    scale = default_oct;
  }
  scale += OCTAVE_OFFSET;
  if(*p == ',') p++;       // skip comma
    long which = random (3, 6);
// now play the note
  if(note) {
    tone1.play(notes[(scale - 4) * 12 + note]);
    delay(duration);
   
    LEDs[which] = 1 - LEDs[which];
    digitalWrite(which, LEDs[which]);
    tone1.stop();
  }
}
}
}
 
 

Preview

Preview: Arduino Christmas Tree 1/3   
Preview: Arduino Christmas Tree 2/3   
Preview: Arduino Christmas Tree 3/3