bubdan

Jesus Christ Is Risen Today

May 15th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1.  #include "pitches.h"
  2.  
  3. // notes in the melody: 0, = REST
  4. int melody[] = {
  5.   NOTE_D4, NOTE_FS4, NOTE_A5, NOTE_D4,
  6.   NOTE_G4, NOTE_B5, NOTE_B5, NOTE_A5,
  7.   NOTE_FS4, NOTE_G4, NOTE_A5, NOTE_D4,
  8.   NOTE_G4, NOTE_FS4, NOTE_G4, NOTE_FS4,
  9.   NOTE_E4, NOTE_D4,
  10.  
  11.   NOTE_G4, NOTE_A5, NOTE_B5, NOTE_A5,
  12.   NOTE_G4, NOTE_FS4, NOTE_FS4, NOTE_E4,
  13.   NOTE_FS4, NOTE_G4, NOTE_A5, NOTE_D4, NOTE_G4, NOTE_FS4, NOTE_G4,
  14.   NOTE_FS4, NOTE_E4, NOTE_D4,
  15.  
  16.   NOTE_CS5, NOTE_D5, NOTE_E5, NOTE_A4,
  17.   NOTE_D5, NOTE_E5, NOTE_FS5,
  18.   NOTE_CS5, NOTE_D5, NOTE_E5, NOTE_A4, NOTE_D5, NOTE_CS5, NOTE_D5,
  19.   NOTE_CS5, NOTE_B4, NOTE_A4,
  20.  
  21.   NOTE_A4, NOTE_C5, NOTE_D5, NOTE_FS4,
  22.   NOTE_G4, NOTE_B4, NOTE_B4, NOTE_A4,
  23.   NOTE_D5, NOTE_C5, NOTE_D5, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5,
  24.   NOTE_D5, NOTE_C5, NOTE_D5
  25. };
  26.  
  27. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  28. int noteDurations[] = {
  29.   4, 4, 4, 4, /**/ 4, 4, 4, 4, /**/ 8, 8, 8, 8, 4, 8, 8,/**/ 4, 4, 2,
  30.  
  31.   4, 4, 4, 4, /**/ 4, 4, 4, 4, /**/ 8, 8, 8, 8, 4, 8, 8,/**/ 4, 4, 2,
  32.  
  33.   4, 4, 4, 4, /**/ 4, 4, 2, /**/ 8, 8, 8, 8, 4, 8, 8, /**/ 4, 4, 2,
  34.  
  35.   4, 4, 4, 4, /**/ 4, 4, 4, 4, /**/ 8, 8, 8, 8, 8, 8, 8, 8, /**/ 4, 4, 2
  36. };
  37.  
  38. void setup() {
  39.   int numSize = 0; //this tells us the size of a int
  40.   int numNotes = sizeof(noteDurations)/sizeof(numSize);
  41.   // iterate over the notes of the melody:
  42.   for (int thisNote = 0; thisNote < numNotes; thisNote++) {
  43.  
  44.     // to calculate the note duration, take one second
  45.     // divided by the note type.
  46.     //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  47.     int noteDuration = 1000/noteDurations[thisNote];
  48.     tone(8, melody[thisNote],noteDuration);
  49.  
  50.     // to distinguish the notes, set a minimum time between them.
  51.     // the note's duration + 30% seems to work well:
  52.     int pauseBetweenNotes = noteDuration * 1.30;
  53.     delay(pauseBetweenNotes);
  54.     // stop the tone playing:
  55.     noTone(8);
  56.   }
  57. }
  58.  
  59. void loop() {
  60.   // no need to repeat the hymn.
  61. }
Advertisement
Add Comment
Please, Sign In to add comment