/*
Code for BSENMANSOL Big Shot Defense and Security Department Auto-Sentry Mounted Infrared Tracking Turret V2.0
Code for sensors borrowed from HowToMechatronics
Designed and built by Myles Labnongsang
Code troubleshot and debugged by OpenAI's ChatGPT
Funding provided by the Central Intelligence Agency of the United States of America
Big Shot Manufacturing and Engineering Solutions GmbH is in no way liable for any injury that may be caused or exasperated by the Auto-Sentry Mounted Infrared Tracking Turret
I would like to thank the following-
Walter Hartwell White
Finger
Dell Conagher, PhD, MD, DEng, DA, DBA, DSc, DCS, DIT, DIT, DEnv, DAS, et cetera ad infinitum
James Morgan 'Saul Goodman' McGill
Dr. Ivo Robotnik, PhD
Justin Peter Löwenbräu Griffin
Xi Jinping
The Communist Party of China at large
*/
#include <Servo.h>
Servo sentrygoinup;
Servo sentrydown;
const int trigPin1 = 13;
const int echoPin1 = 12;
const int trigPin2 = 11;
const int echoPin2 = 10;
const int trigPin3 = 9;
const int echoPin3 = 8;
long duration1;
int distance1;
long duration2;
int distance2;
long duration3;
int distance3;
int pirState = LOW;
int val = 0;
int inputPin = 5;
int yeehaw;
void setup() {
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
Serial.begin(9600);
sentrygoinup.attach (7);
sentrydown.attach (6);
}
void loop() {
//You and me, hoss...
//Sentry go go down 'n up 'n DAMMIT! Gotta move that gear!
//This thing ain't on autopilot DAMMIT! Gotta move that gear!
//HOLD IT, Spy! Don't touch that sentry- DAMMIT! Gotta move that gear!
//That Spy ain't on our gear- get down DAMMIT! Gotta move that gear!
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = duration1 * 0.034 / 2;
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = duration2 * 0.034 / 2;
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distance3 = duration3 * 0.034 / 2;
// Shootin' Code
if (distance1 < 100) {
sentrygoinup.write (20);
Serial.println("ENGAGING!");
}
else {
sentrygoinup.write (0);
}
// PIR Sensor Code
val = digitalRead(inputPin);
if (val == HIGH) {
yeehaw = 1;
if (pirState == LOW) {
Serial.println("Start prayin', boy!");
pirState = HIGH;
}
}
else {
yeehaw = 0;
if (pirState == HIGH) {
Serial.println("I told ya, don't touch that darn thing!");
pirState = LOW;
}
}
// Targeting Code
if (distance3 < 200) {
Serial.println("BIG MEAN MOTHER-HUBBARD ON THE RIGHT - TARGETING...");
sentrydown.write (0);
}
else if (distance2 < 200) {
Serial.println("BIG MEAN MOTHER-HUBBARD ON THE LEFT - TARGETING...");
sentrydown.write (180);
}
else {
sentrydown.write (90);
}
}