// Arduino Water Board
// vgmlr
#include "Servo.h"
Servo spigot;
Servo rightarm;
// Servo Position
int spigpos = 45;
int armpos = 15;
// Resting State
float lieset = 0;
int lierec = 0;
int lietotal = 0;
int lieavg = 0;
int lienew = 0;
// Variance
int spvar = 20;
int liepin = A0;
// Valve
int valve = 8;
// LEDs
int blue = 13;
int green = 12;
int red = 11;
void setup() {
spigot.attach(9); // Spigot
rightarm.attach(10); // Rag Arm
pinMode(valve, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
Serial.begin(9600);
// Reset Position
spigot.write(45);
delay(1500);
rightarm.write(15);
digitalWrite(valve, LOW);
// Obtain Resting State -- Calibration
for (int x = 0; x < 100; x++) {
lieavg = analogRead(liepin);
lietotal = lietotal + lieavg;
}
lieset = round(lietotal / 100);
}
void loop() {
Serial.println(analogRead(liepin));
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
// Jacob Communication
if (Serial.available()) {
char ser = Serial.read();
switch (ser) {
case '1':
detect();
break;
}
}
delay(20);
}
void detect() {
// Query GV Response
for (int x = 0; x < 50; x++) {
lieavg = analogRead(liepin);
lietotal = lietotal + lieavg;
Serial.println(analogRead(liepin));
delay(2);
}
lienew = round(lietotal / 50);
// Lie or Truth?
// Jacob Polls Serial Response
if (lienew + spvar > lieset || lienew - spvar > lieset) {
Serial.println("Lie");
torture();
}
else if (lieset > lienew + spvar || lieset > lienew - spvar) {
Serial.println("Truth");
truth();
}
else {
Serial.println("Unclear")
detect();
}
}
void torture() {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
for (armpos = 15; armpos <= 85; armpos += 1) {
rightarm.write(armpos);
delay(15);
}
for (spigpos = 45; spigpos <= 90; spigpos += 1) {
spigot.write(spigpos);
delay(15);
}
delay(1500);
digitalWrite(valve, HIGH);
delay(10000);
digitalWrite(valve, LOW);
spigot.write(45);
delay(1500);
rightarm.write(15);
}
void truth() {
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
}