Guest User

WTF?!?!?!

a guest
Mar 24th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.07 KB | None | 0 0
  1. //definuje tóny. číslo je frekvence tónu (ze stránky http://www.kytara.net/struny/tabulka-not-frekvenci-a-vlnovych-delek) S = #
  2. #define C1  33
  3. #define CS1 35
  4. #define D1  37
  5. #define DS1 39
  6. #define E1  41
  7. #define F1  44
  8. #define FS1 46
  9. #define G1  49
  10. #define GS1 52
  11. #define A1  55
  12. #define AS1 58
  13. #define B1  62
  14. #define C2  65
  15. #define CS2 69
  16. #define D2  73
  17. #define DS2 78
  18. #define E2  82
  19. #define F2  87
  20. #define FS2 93
  21. #define G2  98
  22. #define GS2 104
  23. #define A2  110
  24. #define AS2 117
  25. #define B2  123
  26. #define C3  131
  27. #define CS3 139
  28. #define D3  147
  29. #define DS3 156
  30. #define E3  165
  31. #define F3  175
  32. #define FS3 185
  33. #define G3  196
  34. #define GS3 208
  35. #define A3  220
  36. #define AS3 233
  37. #define B3  247
  38. #define C4  262
  39. #define CS4 277
  40. #define D4  294
  41. #define DS4 311
  42. #define E4  330
  43. #define F4  349
  44. #define FS4 370
  45. #define G4  392
  46. #define GS4 415
  47. #define A4  440
  48. #define AS4 466
  49. #define B4  494
  50. #define C5  523
  51. #define CS5 554
  52. #define D5  587
  53. #define DS5 622
  54. #define E5  659
  55. #define F5  698
  56. #define FS5 740
  57. #define G5  784
  58. #define GS5 831
  59. #define A5  880
  60. #define AS5 932
  61. #define B5  988
  62. #define C6  1047
  63. #define CS6 1109
  64. #define D6  1175
  65. #define DS6 1245
  66. #define E6  1319
  67. #define F6  1397
  68. #define FS6 1480
  69. #define G6  1568
  70. #define GS6 1661
  71. #define A6  1760
  72. #define AS6 1865
  73. #define B6  1976
  74. #define C7  2093
  75. #define CS7 2217
  76. #define D7  2349
  77. #define DS7 2489
  78. #define E7  2637
  79. #define F7  2794
  80. #define FS7 2960
  81. #define G7  3136
  82. #define GS7 3322
  83. #define A7  3520
  84. #define AS7 3729
  85. #define B7  3951
  86. #define C8  4186
  87. #define CS8 4435
  88. #define D8  4699
  89. #define DS8 4978
  90.  
  91. // Co se rychlosti týce, tak je standardní délka celé noty 1000s
  92. //noty https://www.google.cz/search?q=ode+to+joy+notes&biw=1920&bih=979&tbm=isch&tbo=u&source=univ&sa=X&sqi=2&ved=0ahUKEwjampj0m9fLAhXGPBQKHX48AYsQsAQIGg#imgrc=rk14U7iDg_jsZM%3A
  93. int otj[] =  //ode to joy nastavení melodie, délka not se nastaví v příštím kroku (62 not)
  94. {
  95.   E4, E4, F4, G4, G4, F4, E4, D4, C4, C4, D4, E4, E4, D4, D4,
  96.   E4, E4, F4, G4, G4, F4, E4, D4, C4, C4, D4, E4, D4, C4, C4,
  97.   D4, D4, E4, C4, D4, F4, E4, C4, D4, F4, E4, D4, C4, D4, G4,
  98.   E4, E4, F4, G4, G4, F4, E4, D4, C4, C4, D4, E4, D4, C4, C4
  99. };
  100. int mario[] =
  101. {
  102.   E7, E7, 0, E7, 0, C7, E7, 0,
  103.   G7, 0, 0,  0, G6, 0, 0, 0,
  104.  
  105.   C7, 0, 0, G6, 0, 0, E6, 0,
  106.   0, A6, 0, B6, 0, AS6, A6, 0,
  107.  
  108.   G6, E7, G7, A7, 0, F7, G7,
  109.   0, E7, 0, C7, D7, B6, 0, 0,
  110.  
  111.   C7, 0, 0, G6, 0, 0, E6, 0,
  112.   0, A6, 0, B6, 0, AS6, A6, 0,
  113.  
  114.   G6, E7, G7, A7, 0, F7, G7,
  115.   0, E7, 0, C7, D7, B6, 0, 0
  116. };
  117. int otjr[] = //nastavuji rytmus 4 - 1/4 nota 2 - 1/2 nota
  118. {
  119.   4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,
  120.   4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,
  121.   4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,
  122.   4,4,4,4,4,4,4,4,4,4,4,4,4,4,2
  123. };
  124. int marior[] = {
  125.   12, 12, 12, 12,
  126.   12, 12, 12, 12,
  127.   12, 12, 12, 12,
  128.   12, 12, 12, 12,
  129.  
  130.   12, 12, 12, 12,
  131.   12, 12, 12, 12,
  132.   12, 12, 12, 12,
  133.   12, 12, 12, 12,
  134.  
  135.   9, 9, 9,
  136.   12, 12, 12, 12,
  137.   12, 12, 12, 12,
  138.   12, 12, 12, 12,
  139.  
  140.   12, 12, 12, 12,
  141.   12, 12, 12, 12,
  142.   12, 12, 12, 12,
  143.   12, 12, 12, 12,
  144.  
  145.   9, 9, 9,
  146.   12, 12, 12, 12,
  147.   12, 12, 12, 12,
  148.   12, 12, 12, 12,
  149. };
  150.  
  151. int t1 = 3;
  152. int t2 = 4;
  153. int cteni1;
  154. int cteni2;
  155.  
  156. void setup() {
  157.     pinMode(t1, INPUT);
  158.     pinMode(t2, INPUT);
  159.     cteni1 = digitalRead(t1);
  160.     cteni2 = digitalRead(t2);
  161. }
  162.  
  163. void loop() {
  164.   if (digitalRead(cteni1 == HIGH))
  165.     {
  166.         // přehrání melodie otj
  167.         for (int tnota = 0; tnota < 63; tnota++)
  168.         {
  169.           //zjištění délky noty
  170.           int dnot = 1000/otjr[tnota];
  171.           tone(2, otj[tnota],dnot); //port2
  172.           int mnot = dnot * 1.30;
  173.           delay(mnot);
  174.           //zastavení přehrávaného tónu, ať do konce života nehraje poslední tón
  175.           noTone(62);    
  176.         }
  177.     }
  178.   else if (digitalRead(cteni2 == HIGH))
  179.      {
  180.       for (int tnota2 = 0; tnota2 < 270; tnota2++)
  181.         {
  182.           int dnot2 = 1000/marior[tnota2];
  183.           tone(2, mario[tnota2],dnot2); //port2
  184.           int mnot2 = dnot2 * 1.30;
  185.           delay(mnot2);
  186.           noTone(270);    
  187.         }
  188.      }
  189.  
  190. }
Add Comment
Please, Sign In to add comment