Arduino Beatdet



  1. // Arduino Beatdet Bidet
  2. // pkvi
  3. // MSGEQ7 Script | J Skoba
  4. // WTV020-SD-16P | Diego J. Arevalo
  5. #include "Servo.h"
  6. #include "Wtv020sd16p.h"
  7. // Servo
  8. Servo sprayarm;
  9. int pos = 45;
  10. // Music Player
  11. int resetPin = 14;
  12. int clockPin = 15;
  13. int dataPin = 16;
  14. int busyPin = 17;
  15. Wtv020sd16p wtv020sd16p(resetPin, clockPin, dataPin, busyPin);
  16. // EQ Pins
  17. int analogPin = A2;
  18. int strobePin = 2;
  19. int resetPin = 3;
  20. int spectrumValue[7];
  21. // LED Pins
  22. int one = 8;
  23. int two = 9;
  24. int thr = 10;
  25. int fou = 11;
  26. // LED Variables
  27. int ledone = 0;
  28. int ledtwo = 0;
  29. int ledthr = 0;
  30. int ledfou = 0;
  31. // Pump Pins
  32. int pumpo = 4;
  33. int pumpt = 5;
  34. int pumph = 6;
  35. int pumpf = 7;
  36. // Pump Variables
  37. int pmpone = 0;
  38. int pmptwo = 0;
  39. int pmpthr = 0;
  40. int pmpfou = 0;
  41. // BlueTeethes
  42. char inbound = 0;
  43. void setup()
  44. {
  45. Serial.begin(9600);
  46. wtv020sd16p.reset();
  47. sprayarm.attach(12);
  48. sprayarm.write(pos);
  49. pinMode(analogPin, INPUT);
  50. pinMode(strobePin, OUTPUT);
  51. pinMode(resetPin, OUTPUT);
  52. analogReference(DEFAULT);
  53. pinMode(one, OUTPUT);
  54. pinMode(two, OUTPUT);
  55. pinMode(thr, OUTPUT);
  56. pinMode(fou, OUTPUT);
  57. pinMode(pumpo, OUTPUT);
  58. pinMode(pumpt, OUTPUT);
  59. pinMode(pumph, OUTPUT);
  60. pinMode(pumpf, OUTPUT);
  61. digitalWrite(resetPin, LOW);
  62. digitalWrite(strobePin, HIGH);
  63. }
  64. void loop()
  65. {
  66. // Clear Audio
  67. wtv020sd16p.stopVoice();
  68. // Wait for Track
  69. if (Serial.available() > 0)
  70. {
  71. // Which Track Number
  72. inbound = Serial.read();
  73. if (inbound == '1') {
  74. // Track 1
  75. armout();
  76. wtv020sd16p.playVoice(0);
  77. spray();
  78. wtv020sd16p.stopVoice();
  79. armin();
  80. }
  81. else if (inbound == '2') {
  82. // Track 2
  83. armout();
  84. wtv020sd16p.playVoice(1);
  85. spray();
  86. wtv020sd16p.stopVoice();
  87. armin();
  88. }
  89. else if (inbound == '3') {
  90. // Track 3
  91. armout();
  92. wtv020sd16p.playVoice(2);
  93. spray();
  94. wtv020sd16p.stopVoice();
  95. armin();
  96. }
  97. }
  98. }
  99. // Arm Out
  100. void armout() {
  101. for (pos = 45; pos <= 97; pos += 1) {
  102. sprayarm.write(pos);
  103. delay(15);
  104. }
  105. }
  106. // Arm In
  107. void armin() {
  108. for (pos = 97; pos >= 45; pos -= 1) {
  109. sprayarm.write(pos);
  110. delay(15);
  111. }
  112. }
  113. void spray() {
  114. // Loop 15 Seconds
  115. for (int t = 0; t < 5000000, t++) {
  116. // EQ Reset
  117. digitalWrite(resetPin, HIGH);
  118. digitalWrite(resetPin, LOW);
  119. // EQ Store Values and Print
  120. for (int p = 0; p < 7; p++)
  121. {
  122. digitalWrite(strobePin, LOW);
  123. delayMicroseconds(30);
  124. spectrumValue[p] = analogRead(analogPin);
  125. // Serial.print(" ");
  126. // Serial.print(spectrumValue[p]);
  127. digitalWrite(strobePin, HIGH);
  128. }
  129. // Serial.println();
  130. // Map Audio to LED and Pumps
  131. ledone = spectrumValue[0];
  132. // Constrain Required to Limit Results
  133. ledone = constrain(ledone, 400, 600);
  134. // Lower Power to Lower Elevation
  135. ledone = map(ledone, 400, 600, 0, 190);
  136. analogWrite(fou, ledone); // 0
  137. analogWrite(pumpf, ledone); // 0
  138. // Serial.print(ledone);
  139. // Serial.print(" ");
  140. ledtwo = spectrumValue[1];
  141. ledtwo = constrain(ledtwo, 550, 600);
  142. ledtwo = map(ledtwo, 550, 600, 0, 190);
  143. analogWrite(one, ledtwo); // 1
  144. analogWrite(pumpo, ledtwo); // 1
  145. // Serial.print(ledtwo);
  146. // Serial.print(" ");
  147. ledthr = spectrumValue[4];
  148. ledthr = constrain(ledthr, 130, 160);
  149. ledthr = map(ledthr, 130, 160, 0, 190);
  150. analogWrite(two, ledthr); // 2
  151. analogWrite(pumpt, ledthr); // 2
  152. // Serial.print(ledthr);
  153. // Serial.print(" ");
  154. ledfou = spectrumValue[6];
  155. ledfou = constrain(ledfou, 110, 150);
  156. ledfou = map(ledfou, 110, 150, 0, 190);
  157. analogWrite(thr, ledfou); // 4
  158. analogWrite(pumph, ledfou); // 4
  159. // Serial.print(ledfou);
  160. // Serial.println();
  161. }
  162. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,364 miters
123 tenons
Subscribe
0.0035