]> git.piffa.net Git - sketchbook_andrea/blob - piezo/piezo_4_1_james_bond/piezo_4_1_james_bond.ino
piezo
[sketchbook_andrea] / piezo / piezo_4_1_james_bond / piezo_4_1_james_bond.ino
1 // From: http://garagelab.com/profiles/blogs/how-to-use-tone-function-arduino-playing-the-james-bond-theme
2
3 #include "pitches.h"
4 #define NO_SOUND 0 // make the rests in music
5
6 //array of notes
7 int melody[] = {
8   /*NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,
9    NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,
10    NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
11    NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,*/
12    //Introduction
13   NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
14   NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
15   NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
16   NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
17   NOTE_DS5,NOTE_D5,NOTE_B4,NOTE_A4,NOTE_B4,
18   NOTE_E4,NOTE_G4,NOTE_DS5,NOTE_D5,NOTE_G4,NOTE_B4,
19   NOTE_B4,NOTE_FS5,NOTE_F5,NOTE_B4,NOTE_D5,NOTE_AS5,
20   NOTE_A5,NOTE_F5,NOTE_A5,NOTE_DS6,NOTE_D6,NO_SOUND
21 };
22
23 // note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.
24 int noteDurations[] = {
25   /*8,8,2,8,8,2,16,8,16,8,8,
26    2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,
27    8,16,16,8,4,8,8,8,
28    8,16,16,8,4,8,8,8,*/
29   8,16,16,8,4,8,8,8,
30   8,16,16,8,4,8,8,8,
31   8,16,16,8,4,8,8,8,
32   8,16,16,8,4,8,8,8,
33   8,2,8,8,1,
34   8,4,8,4,8,8,
35   8,8,4,8,4,8,
36   4,8,4,8,3
37 };
38
39 int pace = 1450; // change pace of music("speedy")
40 void setup() {
41   for (int Note = 0; Note <54; Note++) {//counter of Notes (54 limit the array)
42     int duration = pace/noteDurations[Note];//Adjust duration with the pace of music
43     tone(9, melody[Note],duration); //Play note
44
45 // to distinguish the notes, set a minimum time between them.
46     delay(duration*1.2);
47   }
48 }
49
50 void loop() {
51   //to repeat song, push reset button.
52 }
53 //End of Sketch