Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement