Guest User

Untitled

a guest
Dec 18th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. /**********************************************************
  2.  
  3. 5 mélodies de Noël jouées par l'Arduino
  4.  
  5. ************************************************************/
  6.  
  7. #define sortie 8 // sortie du son à la broche 8 de l'Arduino
  8.  
  9. // fréquence associée à chaque note
  10. // do, do#, ré, ré#, mi, fa, fa#, sol, sol#, la, la#, si
  11. const float note[12] = {65.41, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.83, 110.00, 116.54, 123.47
  12. };
  13.  
  14. // chaque note de la mélodie comporte 3 paramètres:
  15. // note (de 0 à 11: 0 pour do, 1 pour do#, etc)
  16. // octave (1 à 3)
  17. // durée (1 pour croche, 2 pour noire, 4 pour ronde)
  18.  
  19. void jingleBells(void) {
  20.  
  21. // Vive le vent
  22.  
  23. const int nombreDeNotes = 49;
  24. const int tempo = 150; // plus c'est petit, plus c'est rapide
  25. const int melodie[][3] = { {4, 2, 2}, {4, 2, 2}, {4, 2, 4}, {4, 2, 2}, {4, 2, 2}, {4, 2, 4},
  26. {4, 2, 2}, {7, 2, 2}, {0, 2, 3}, {2, 2, 1}, {4, 2, 8},
  27. {5, 2, 2}, {5, 2, 2}, {5, 2, 3}, {5, 2, 1}, {5, 2, 2}, {4, 2, 2}, {4, 2, 3},
  28. {4, 2, 1}, {4, 2, 2}, {2, 2, 2}, {2, 2, 2}, {4, 2, 2}, {2, 2, 4}, {7, 2, 4},
  29. {4, 2, 2}, {4, 2, 2}, {4, 2, 4}, {4, 2, 2}, {4, 2, 2}, {4, 2, 4},
  30. {4, 2, 2}, {7, 2, 2}, {0, 2, 3}, {2, 2, 1}, {4, 2, 8},
  31. {5, 2, 2}, {5, 2, 2}, {5, 2, 3}, {5, 2, 1}, {5, 2, 2}, {4, 2, 2}, {4, 2, 3},
  32. {4, 2, 1}, {7, 2, 2}, {7, 2, 2}, {5, 2, 2}, {2, 2, 2}, {0, 2, 8}
  33. };
  34.  
  35. int frequence;
  36.  
  37. for ( int i = 0; i < nombreDeNotes ; i++ ) {
  38. frequence = round(note[melodie[i][0]] * 2 * (melodie[i][1] - 1));
  39.  
  40. tone(sortie, frequence);
  41. delay(tempo * melodie[i][2] - 50);
  42. noTone(sortie);
  43. delay(50);
  44.  
  45. }
  46.  
  47.  
  48. }
  49.  
  50.  
  51. void weWishYou (void) {
  52.  
  53. // We wish you a merry Christmas
  54.  
  55. const int nombreDeNotes = 29;
  56. const int tempo = 150 ; // plus c'est petit, plus c'est rapide
  57. const int melodie[][3] = { {7, 2, 2}, {0, 3, 2}, {0, 3, 1}, {2, 3, 1}, {0, 3, 1}, {11, 2, 1},
  58. {9, 2, 2}, {9, 2, 2}, {9, 2, 2}, {2, 3, 2}, {2, 3, 1}, {4, 3, 1}, {2, 3, 1}, {0, 3, 1},
  59. {11, 2, 2}, {7, 2, 2}, {7, 2, 2}, {4, 3, 2}, {4, 3, 1}, {5, 3, 1}, {4, 3, 1}, {2, 3, 1},
  60. {0, 3, 2}, {9, 2, 2}, {7, 2, 2}, {9, 2, 2}, {2, 3, 2}, {11, 2, 2}, {0, 3, 4}
  61. };
  62.  
  63. int frequence;
  64.  
  65. for ( int i = 0; i < nombreDeNotes ; i++ ) {
  66. frequence = round(note[melodie[i][0]] * 2 * (melodie[i][1] - 1));
  67.  
  68. tone(sortie, frequence);
  69. delay(tempo * melodie[i][2] - 50);
  70. noTone(sortie);
  71. delay(50);
  72.  
  73. }
  74.  
  75. }
  76.  
  77. void petitRenne (void) {
  78.  
  79. // le petit renne au nez rouge
  80.  
  81. const int nombreDeNotes = 56;
  82. const int tempo = 200 ; // plus c'est petit, plus c'est rapide
  83. const int melodie[][3] = { {7, 2, 2}, {9, 2, 1}, {7, 2, 1}, {4, 2, 2}, {0, 3, 2}, {9, 2, 2}, {7, 2, 6},
  84. {7, 2, 1}, {9, 2, 1}, {7, 2, 1}, {9, 2, 1}, {7, 2, 2}, {0, 3, 2}, {11, 2, 6},
  85. {5, 2, 2}, {7, 2, 1}, {5, 2, 1}, {2, 2, 2}, {11, 2, 2}, {9, 2, 2}, {7, 2, 6},
  86. {7, 2, 1}, {9, 2, 1}, {7, 2, 1}, {9, 2, 1}, {7, 2, 2}, {9, 2, 2}, {4, 2, 6},
  87. {7, 2, 2}, {9, 2, 1}, {7, 2, 1}, {4, 2, 2}, {0, 3, 2}, {9, 2, 2}, {7, 2, 6},
  88. {7, 2, 1}, {9, 2, 1}, {7, 2, 1}, {9, 2, 1}, {7, 2, 2}, {0, 3, 2}, {11, 2, 6},
  89. {5, 2, 2}, {7, 2, 1}, {5, 2, 1}, {2, 2, 2}, {11, 2, 2}, {9, 2, 2}, {7, 2, 6},
  90. {7, 2, 1}, {9, 2, 1}, {7, 2, 1}, {9, 2, 1}, {7, 2, 2}, {2, 3, 2}, {0, 3, 6},
  91. };
  92.  
  93. int frequence;
  94.  
  95. for ( int i = 0; i < nombreDeNotes ; i++ ) {
  96. frequence = round(note[melodie[i][0]] * 2 * (melodie[i][1] - 1));
  97.  
  98. tone(sortie, frequence);
  99. delay(tempo * melodie[i][2] - 50);
  100. noTone(sortie);
  101. delay(50);
  102.  
  103. }
  104.  
  105. }
  106.  
  107. void petitPapa(void) {
  108. // petit papa noël
  109. const int nombreDeNotes = 58;
  110. const int tempo = 250 ; // plus c'est petit, plus c'est rapide
  111. const int melodie[][3] = { {7, 2, 2}, {0, 3, 2}, {0, 3, 2}, {0, 3, 2}, {2, 3, 2}, {0, 3, 6},
  112. {0, 3, 1}, {2, 3, 1}, {4, 3, 2}, {4, 3, 2}, {4, 3, 2}, {5, 3, 2}, {4, 3, 6},
  113. {2, 3, 2}, {0, 3, 3}, {0, 3, 1}, {0, 3, 1}, {0, 3, 1}, {11, 2, 1}, {9, 2, 1}, {7, 2, 6},
  114. {7, 2, 1}, {7, 2, 1}, {0, 3, 4}, {0, 3, 1}, {0, 3, 1}, {11, 2, 1}, {0, 3, 1}, {2, 3, 6},
  115. {7, 2, 2}, {0, 3, 2}, {0, 3, 2}, {0, 3, 2}, {2, 3, 2}, {0, 3, 6},
  116. {0, 3, 1}, {2, 3, 1}, {4, 3, 2}, {4, 3, 2}, {4, 3, 2}, {5, 3, 2}, {4, 3, 6},
  117. {2, 3, 2}, {0, 3, 3}, {0, 3, 1}, {0, 3, 1}, {0, 3, 1}, {11, 2, 1}, {9, 2, 1}, {7, 2, 6},
  118. {7, 2, 1}, {7, 2, 1}, {0, 3, 4}, {0, 3, 1}, {0, 3, 1}, {2, 3, 1}, {2, 3, 1}, {0, 3, 6},
  119. };
  120.  
  121.  
  122. int frequence;
  123.  
  124. for ( int i = 0; i < nombreDeNotes ; i++ ) {
  125. frequence = round(note[melodie[i][0]] * 2 * (melodie[i][1] - 1));
  126.  
  127. tone(sortie, frequence);
  128. delay(tempo * melodie[i][2] - 50);
  129. noTone(sortie);
  130. delay(50);
  131.  
  132. }
  133. }
  134.  
  135.  
  136. void auRoyaume (void) {
  137.  
  138. //Au royaume du bonhomme hiver (Winter Wonderland)
  139.  
  140. const int nombreDeNotes = 33;
  141. const int tempo = 150 ; // plus c'est petit, plus c'est rapide
  142. const int melodie[][3] = { {7, 2, 2}, {7, 2, 1}, {7, 2, 9}, {7, 2, 2}, {7, 2, 1}, {4, 2, 2}, {7, 2, 6},
  143. {7, 2, 2}, {7, 2, 1}, {7, 2, 9}, {7, 2, 2}, {7, 2, 1}, {5, 2, 2}, {7, 2, 6},
  144. {7, 2, 1}, {11, 2, 2}, {11, 2, 1}, {11, 2, 2}, {9, 2, 6},
  145. {9, 2, 1}, {7, 2, 2}, {7, 2, 1}, {7, 2, 2}, {5, 2, 6},
  146. {4, 2, 2}, {4, 2, 1}, {4, 2, 2}, {4, 2, 1}, {2, 2, 2}, {2, 2, 1}, {2, 2, 1}, {2, 2, 1}, {0, 2, 9},
  147. };
  148.  
  149. int frequence;
  150.  
  151. for ( int i = 0; i < nombreDeNotes ; i++ ) {
  152. frequence = round(note[melodie[i][0]] * 2 * (melodie[i][1] - 1));
  153.  
  154. tone(sortie, frequence);
  155. delay(tempo * melodie[i][2] - 50);
  156. noTone(sortie);
  157. delay(50);
  158.  
  159. }
  160. }
  161.  
  162. void setup() {
  163.  
  164.  
  165. }
  166.  
  167. void loop() {
  168.  
  169. jingleBells();
  170. delay (2000);
  171. weWishYou ();
  172. delay (2000);
  173. petitRenne();
  174. delay (2000);
  175. petitPapa();
  176. delay (2000);
  177. auRoyaume();
  178. delay (2000);
  179.  
  180. }
Add Comment
Please, Sign In to add comment