gabbyshimoni icon

sevivon

gabbyshimoni | PRO | 12/03/20 04:03:58 PM UTC | 0 ⭐ | 1074 👁️ | Never ⏰ | []
C++ |

840 B

|

None

|

0 👍

/

0 👎

#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_A4, NOTE_A4,NOTE_B4, NOTE_C5, NOTE_C5,NOTE_B4, NOTE_E5, NOTE_E5,NOTE_D5,NOTE_C5,NOTE_B4,NOTE_A4, NOTE_C5, NOTE_C5,NOTE_B4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
 
int noteDurations[] = {
   8, 8, 4, 8,8,4,8,8,16,16,16,16,8,8,4 
};
 
void setup() {
   // iterate over the notes of the melody:
   for (int thisNote = 0; thisNote < 15; 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 = 1000/noteDurations[thisNote];
      tone(8, melody[thisNote],noteDuration);
      //pause for the note's duration plus 30 ms:
      delay(noteDuration +30);
   }
}
 
void loop() {
   // no need to repeat the melody.
}

Comments