Advertisement
uaa

_eman_8.cpp output from toneMelody.ino

uaa
Mar 16th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #line 1 "toneMelody.ino"
  2. /*
  3. Melody
  4.  
  5. Plays a melody
  6.  
  7. circuit:
  8. * 8-ohm speaker on digital pin 8
  9.  
  10. created 21 Jan 2010
  11. modified 30 Aug 2011
  12. by Tom Igoe
  13.  
  14. This example code is in the public domain.
  15.  
  16. http://arduino.cc/en/Tutorial/Tone
  17.  
  18. */
  19. #include "pitches.h"
  20.  
  21. // notes in the melody:
  22. #include "Arduino.h"
  23. void setup();
  24. void loop();
  25. #line 21
  26. int melody[] = {
  27. NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
  28.  
  29. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  30. int noteDurations[] = {
  31. 4, 8, 8, 4,4,4,4,4 };
  32.  
  33. void setup() {
  34. // iterate over the notes of the melody:
  35. for (int thisNote = 0; thisNote < 8; thisNote++) {
  36.  
  37. // to calculate the note duration, take one second
  38. // divided by the note type.
  39. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  40. int noteDuration = 1000/noteDurations[thisNote];
  41. tone(8, melody[thisNote],noteDuration);
  42.  
  43. // to distinguish the notes, set a minimum time between them.
  44. // the note's duration + 30% seems to work well:
  45. int pauseBetweenNotes = noteDuration * 1.30;
  46. delay(pauseBetweenNotes);
  47. // stop the tone playing:
  48. noTone(8);
  49. }
  50. }
  51.  
  52. void loop() {
  53. // no need to repeat the melody.
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement