gabbyshimoni

sevivon

Dec 3rd, 2020
665
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pitches.h"
  2. // notes in the melody:
  3. int melody[] = {
  4. 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};
  5. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  6.  
  7. int noteDurations[] = {
  8.    8, 8, 4, 8,8,4,8,8,16,16,16,16,8,8,4
  9. };
  10.  
  11. void setup() {
  12.    // iterate over the notes of the melody:
  13.    for (int thisNote = 0; thisNote < 15; thisNote++) {
  14.       // to calculate the note duration, take one second
  15.       // divided by the note type.
  16.       //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  17.       int noteDuration = 1000/noteDurations[thisNote];
  18.       tone(8, melody[thisNote],noteDuration);
  19.       //pause for the note's duration plus 30 ms:
  20.       delay(noteDuration +30);
  21.    }
  22. }
  23.  
  24. void loop() {
  25.    // no need to repeat the melody.
  26. }
RAW Paste Data