Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Melody
- Plays introduction to take on me by aha
- circuit:
- * 8-ohm speaker on digital pin 8
- */
- #include "pitches.h"
- //notes in the melody:
- int melody[] = { NOTE_FS4, NOTE_FS4,NOTE_D4, NOTE_B3, NOTE_B3,NOTE_E4, NOTE_E4, NOTE_E4, NOTE_GS4,NOTE_GS4,NOTE_A4,NOTE_B4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_E4,NOTE_D4,NOTE_FS4,
- NOTE_FS4,NOTE_FS4,NOTE_E4,NOTE_E4,NOTE_FS4,NOTE_E4};
- // note durations: 4 = quart note, 8 = eigth note, etc:
- int noteDurations[] = { 8, 8, 8, 4,4,4,4,4,8,8,8,8,8,8,8,4,4,4,4,8,8,8,8};
- void setup() {
- // put your setup code here, to run once:
- // iterate over the notes of the melody:
- for (int thisNote = 0; thisNote < 24; thisNote++) {
- // to calc the note duration take 1 sec and divide by note type
- int noteDuration = 1000/noteDurations[thisNote];
- tone(8, melody[thisNote],noteDuration);
- // to distinguish the notes, set a minimum time between them. the note's duration + 30% seems to work well:
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- // stop the tone playing:
- noTone(8);
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- // no need to repeat the melody
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement