arduino star wars imperial march song


SUBMITTED BY: Guest

DATE: Jan. 27, 2014, 1:48 p.m.

FORMAT: Text only

SIZE: 2.7 kB

HITS: 954

  1. const int c = 261;
  2. const int d = 294;
  3. const int e = 329;
  4. const int f = 349;
  5. const int g = 391;
  6. const int gS = 415;
  7. const int a = 440;
  8. const int aS = 455;
  9. const int b = 466;
  10. const int cH = 523;
  11. const int cSH = 554;
  12. const int dH = 587;
  13. const int dSH = 622;
  14. const int eH = 659;
  15. const int fH = 698;
  16. const int fSH = 740;
  17. const int gH = 784;
  18. const int gSH = 830;
  19. const int aH = 880;
  20. const int buzzerPin = 8;
  21. const int ledPin1 = 9;
  22. const int ledPin2 = 13;
  23. int counter = 0;
  24. void setup()
  25. {
  26. //Setup pin modes
  27. pinMode(buzzerPin, OUTPUT);
  28. pinMode(ledPin1, OUTPUT);
  29. pinMode(ledPin2, OUTPUT);
  30. }
  31. void loop()
  32. {
  33. //Play first section
  34. firstSection();
  35. //Play second section
  36. secondSection();
  37. //Variant 1
  38. beep(f, 250);
  39. beep(gS, 500);
  40. beep(f, 350);
  41. beep(a, 125);
  42. beep(cH, 500);
  43. beep(a, 375);
  44. beep(cH, 125);
  45. beep(eH, 650);
  46. delay(500);
  47. //Repeat second section
  48. secondSection();
  49. //Variant 2
  50. beep(f, 250);
  51. beep(gS, 500);
  52. beep(f, 375);
  53. beep(cH, 125);
  54. beep(a, 500);
  55. beep(f, 375);
  56. beep(cH, 125);
  57. beep(a, 650);
  58. delay(650);
  59. }
  60. void beep(int note, int duration)
  61. {
  62. //Play tone on buzzerPin
  63. tone(buzzerPin, note, duration);
  64. //Play different LED depending on value of 'counter'
  65. if(counter % 2 == 0)
  66. {
  67. digitalWrite(ledPin1, HIGH);
  68. delay(duration);
  69. digitalWrite(ledPin1, LOW);
  70. }else
  71. {
  72. digitalWrite(ledPin2, HIGH);
  73. delay(duration);
  74. digitalWrite(ledPin2, LOW);
  75. }
  76. //Stop tone on buzzerPin
  77. noTone(buzzerPin);
  78. delay(50);
  79. //Increment counter
  80. counter++;
  81. }
  82. void firstSection()
  83. {
  84. beep(a, 500);
  85. beep(a, 500);
  86. beep(a, 500);
  87. beep(f, 350);
  88. beep(cH, 150);
  89. beep(a, 500);
  90. beep(f, 350);
  91. beep(cH, 150);
  92. beep(a, 650);
  93. delay(500);
  94. beep(eH, 500);
  95. beep(eH, 500);
  96. beep(eH, 500);
  97. beep(fH, 350);
  98. beep(cH, 150);
  99. beep(gS, 500);
  100. beep(f, 350);
  101. beep(cH, 150);
  102. beep(a, 650);
  103. delay(500);
  104. }
  105. void secondSection()
  106. {
  107. beep(aH, 500);
  108. beep(a, 300);
  109. beep(a, 150);
  110. beep(aH, 500);
  111. beep(gSH, 325);
  112. beep(gH, 175);
  113. beep(fSH, 125);
  114. beep(fH, 125);
  115. beep(fSH, 250);
  116. delay(325);
  117. beep(aS, 250);
  118. beep(dSH, 500);
  119. beep(dH, 325);
  120. beep(cSH, 175);
  121. beep(cH, 125);
  122. beep(b, 125);
  123. beep(cH, 250);
  124. delay(350);
  125. }

comments powered by Disqus