Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #define tuneSize 2
  2. // notes in the melody:
  3. const int melody[tuneSize] = {
  4. NOTE_AS3, 0
  5. };
  6.  
  7. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  8. int noteDurations[tuneSize] = {
  9. 6, 16
  10. };
  11.  
  12. void setup() {
  13. // no need to repeat the melody.
  14. // iterate over the notes of the melody:
  15. for (int thisNote = 0; thisNote < tuneSize; thisNote++) {
  16.  
  17. // to calculate the note duration, take one second
  18. // divided by the note type.
  19. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  20. int noteDuration = 1000 / noteDurations[thisNote];
  21. tone(8, melody[thisNote], noteDuration);
  22.  
  23. // to distinguish the notes, set a minimum time between them.
  24. // the note's duration + 30% seems to work well:
  25. int pauseBetweenNotes = noteDuration * 1.30;
  26. delay(pauseBetweenNotes);
  27. // stop the tone playing:
  28. noTone(8);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement