Advertisement
Cookins

Untitled

Mar 19th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1.  
  2. const int c = 261;
  3. const int d = 294;
  4. const int e = 329;
  5. const int f = 349;
  6. const int g = 391;
  7. const int gS = 415;
  8. const int a = 440;
  9. const int aS = 455;
  10. const int b = 466;
  11. const int cH = 523;
  12. const int cSH = 554;
  13. const int dH = 587;
  14. const int dSH = 622;
  15. const int eH = 659;
  16. const int fH = 698;
  17. const int fSH = 740;
  18. const int gH = 784;
  19. const int gSH = 830;
  20. const int aH = 880;
  21.  
  22. const int buzzerPin = 12; // Digital Pin 8
  23.  
  24. int counter = 0;
  25. int val = 0;//sets value variable to 0
  26.  
  27. void setup() {
  28. pinMode(buzzerPin, OUTPUT);
  29. pinMode (13,OUTPUT);//pin 13 is the led pin and speaker
  30. pinMode (9, INPUT);//pin 9 reads the high signal from the PIR
  31. }
  32. void loop () {
  33. val = digitalRead(9);//Pin 9 is initiallly 0
  34. digitalWrite(13,val);//pin thirteen is equal to whatever pin 9 is
  35. delay(100);
  36. digitalWrite(13,LOW);//led turns off
  37. if (val == 1){
  38. //Play first section
  39. firstSection();
  40.  
  41. //Play second section
  42. secondSection();
  43.  
  44. //Variant 1
  45. beep(f, 250);
  46. beep(gS, 500);
  47. beep(f, 350);
  48. beep(a, 125);
  49. beep(cH, 500);
  50. beep(a, 375);
  51. beep(cH, 125);
  52. beep(eH, 650);
  53.  
  54. delay(500);
  55.  
  56. //Repeat second section
  57. secondSection();
  58.  
  59. //Variant 2
  60. beep(f, 250);
  61. beep(gS, 500);
  62. beep(f, 375);
  63. beep(cH, 125);
  64. beep(a, 500);
  65. beep(f, 375);
  66. beep(cH, 125);
  67. beep(a, 650);
  68.  
  69. delay(650);
  70. }
  71.  
  72. void beep(int note, int duration)
  73. {
  74. //Play tone on buzzerPin
  75. tone(buzzerPin, note, duration);
  76.  
  77. //Stop tone on buzzerPin
  78. noTone(buzzerPin);
  79.  
  80. delay(50);
  81.  
  82. //Increment counter
  83. counter++;
  84. }
  85.  
  86. void firstSection()
  87. {
  88. beep(a, 500);
  89. beep(a, 500);
  90. beep(a, 500);
  91. beep(f, 350);
  92. beep(cH, 150);
  93. beep(a, 500);
  94. beep(f, 350);
  95. beep(cH, 150);
  96. beep(a, 650);
  97.  
  98. delay(500);
  99.  
  100. beep(eH, 500);
  101. beep(eH, 500);
  102. beep(eH, 500);
  103. beep(fH, 350);
  104. beep(cH, 150);
  105. beep(gS, 500);
  106. beep(f, 350);
  107. beep(cH, 150);
  108. beep(a, 650);
  109.  
  110. delay(500);
  111. }
  112.  
  113. void secondSection()
  114. {
  115. beep(aH, 500);
  116. beep(a, 300);
  117. beep(a, 150);
  118. beep(aH, 500);
  119. beep(gSH, 325);
  120. beep(gH, 175);
  121. beep(fSH, 125);
  122. beep(fH, 125);
  123. beep(fSH, 250);
  124.  
  125. delay(325);
  126.  
  127. beep(aS, 250);
  128. beep(dSH, 500);
  129. beep(dH, 325);
  130. beep(cSH, 175);
  131. beep(cH, 125);
  132. beep(b, 125);
  133. beep(cH, 250);
  134.  
  135. delay(350);
  136. }
  137.  
  138. }
  139. else{
  140. digitalWrite(12,LOW);
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement