Advertisement
Guest User

Untitled

a guest
Aug 16th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. /*
  2. Melody
  3.  
  4. Plays introduction to take on me by aha
  5.  
  6. circuit:
  7. * 8-ohm speaker on digital pin 8
  8. */
  9. #include "pitches.h"
  10.  
  11. //notes in the melody:
  12. 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,
  13. NOTE_FS4,NOTE_FS4,NOTE_E4,NOTE_E4,NOTE_FS4,NOTE_E4};
  14.  
  15. // note durations: 4 = quart note, 8 = eigth note, etc:
  16. 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};
  17.  
  18. void setup() {
  19. // put your setup code here, to run once:
  20. // iterate over the notes of the melody:
  21. for (int thisNote = 0; thisNote < 24; thisNote++) {
  22.  
  23. // to calc the note duration take 1 sec and divide by note type
  24. int noteDuration = 1000/noteDurations[thisNote];
  25. tone(8, melody[thisNote],noteDuration);
  26.  
  27. // to distinguish the notes, set a minimum time between them. the note's duration + 30% seems to work well:
  28. int pauseBetweenNotes = noteDuration * 1.30;
  29. delay(pauseBetweenNotes);
  30. // stop the tone playing:
  31. noTone(8);
  32. }
  33. }
  34.  
  35. void loop() {
  36. // put your main code here, to run repeatedly:
  37. // no need to repeat the melody
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement