![](images/beatdet_1.jpg)
![](images/beatdet_2.jpg)
- // Arduino Beatdet Bidet
- // pkvi
- // MSGEQ7 Script | J Skoba
- // WTV020-SD-16P | Diego J. Arevalo
- #include "Servo.h"
- #include "Wtv020sd16p.h"
- // Servo
- Servo sprayarm;
- int pos = 45;
- // Music Player
- int resetPin = 14;
- int clockPin = 15;
- int dataPin = 16;
- int busyPin = 17;
- Wtv020sd16p wtv020sd16p(resetPin, clockPin, dataPin, busyPin);
- // EQ Pins
- int analogPin = A2;
- int strobePin = 2;
- int resetPin = 3;
- int spectrumValue[7];
- // LED Pins
- int one = 8;
- int two = 9;
- int thr = 10;
- int fou = 11;
- // LED Variables
- int ledone = 0;
- int ledtwo = 0;
- int ledthr = 0;
- int ledfou = 0;
- // Pump Pins
- int pumpo = 4;
- int pumpt = 5;
- int pumph = 6;
- int pumpf = 7;
- // Pump Variables
- int pmpone = 0;
- int pmptwo = 0;
- int pmpthr = 0;
- int pmpfou = 0;
- // BlueTeethes
- char inbound = 0;
- void setup()
- {
- Serial.begin(9600);
- wtv020sd16p.reset();
- sprayarm.attach(12);
- sprayarm.write(pos);
- pinMode(analogPin, INPUT);
- pinMode(strobePin, OUTPUT);
- pinMode(resetPin, OUTPUT);
- analogReference(DEFAULT);
- pinMode(one, OUTPUT);
- pinMode(two, OUTPUT);
- pinMode(thr, OUTPUT);
- pinMode(fou, OUTPUT);
- pinMode(pumpo, OUTPUT);
- pinMode(pumpt, OUTPUT);
- pinMode(pumph, OUTPUT);
- pinMode(pumpf, OUTPUT);
- digitalWrite(resetPin, LOW);
- digitalWrite(strobePin, HIGH);
- }
- void loop()
- {
- // Clear Audio
- wtv020sd16p.stopVoice();
- // Wait for Track
- if (Serial.available() > 0)
- {
- // Which Track Number
- inbound = Serial.read();
- if (inbound == '1') {
- // Track 1
- armout();
- wtv020sd16p.playVoice(0);
- spray();
- wtv020sd16p.stopVoice();
- armin();
- }
- else if (inbound == '2') {
- // Track 2
- armout();
- wtv020sd16p.playVoice(1);
- spray();
- wtv020sd16p.stopVoice();
- armin();
- }
- else if (inbound == '3') {
- // Track 3
- armout();
- wtv020sd16p.playVoice(2);
- spray();
- wtv020sd16p.stopVoice();
- armin();
- }
- }
- }
- // Arm Out
- void armout() {
- for (pos = 45; pos <= 97; pos += 1) {
- sprayarm.write(pos);
- delay(15);
- }
- }
- // Arm In
- void armin() {
- for (pos = 97; pos >= 45; pos -= 1) {
- sprayarm.write(pos);
- delay(15);
- }
- }
- void spray() {
- // Loop 15 Seconds
- for (int t = 0; t < 5000000, t++) {
- // EQ Reset
- digitalWrite(resetPin, HIGH);
- digitalWrite(resetPin, LOW);
- // EQ Store Values and Print
- for (int p = 0; p < 7; p++)
- {
- digitalWrite(strobePin, LOW);
- delayMicroseconds(30);
- spectrumValue[p] = analogRead(analogPin);
- // Serial.print(" ");
- // Serial.print(spectrumValue[p]);
- digitalWrite(strobePin, HIGH);
- }
- // Serial.println();
- // Map Audio to LED and Pumps
- ledone = spectrumValue[0];
- // Constrain Required to Limit Results
- ledone = constrain(ledone, 400, 600);
- // Lower Power to Lower Elevation
- ledone = map(ledone, 400, 600, 0, 190);
- analogWrite(fou, ledone); // 0
- analogWrite(pumpf, ledone); // 0
- // Serial.print(ledone);
- // Serial.print(" ");
- ledtwo = spectrumValue[1];
- ledtwo = constrain(ledtwo, 550, 600);
- ledtwo = map(ledtwo, 550, 600, 0, 190);
- analogWrite(one, ledtwo); // 1
- analogWrite(pumpo, ledtwo); // 1
- // Serial.print(ledtwo);
- // Serial.print(" ");
- ledthr = spectrumValue[4];
- ledthr = constrain(ledthr, 130, 160);
- ledthr = map(ledthr, 130, 160, 0, 190);
- analogWrite(two, ledthr); // 2
- analogWrite(pumpt, ledthr); // 2
- // Serial.print(ledthr);
- // Serial.print(" ");
- ledfou = spectrumValue[6];
- ledfou = constrain(ledfou, 110, 150);
- ledfou = map(ledfou, 110, 150, 0, 190);
- analogWrite(thr, ledfou); // 4
- analogWrite(pumph, ledfou); // 4
- // Serial.print(ledfou);
- // Serial.println();
- }
- }