Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define tuneSize 2
- // notes in the melody:
- const int melody[tuneSize] = {
- NOTE_AS3, 0
- };
- // note durations: 4 = quarter note, 8 = eighth note, etc.:
- int noteDurations[tuneSize] = {
- 6, 16
- };
- void setup() {
- // no need to repeat the melody.
- // iterate over the notes of the melody:
- for (int thisNote = 0; thisNote < tuneSize; 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);
- // 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement