Here's the basic structure. Thanks for looking at it.
static char mode;
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int FLASH_PIN = 13;
int MIC_PIN = 0;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup()
{
Serial.begin(115200);
pinMode(MIC_PIN, INPUT);
pinMode(FLASH_PIN, OUTPUT);
}
void loop()
{
if(Serial.available())
{
char mode = Serial.read();
Serial.println(mode);
switch(mode)
{
case '1':
Sound();
break;
case '2':
Ultrasonic();
break;
case '3':
Proximity();
break;
case '4':
Magnetic();
break;
case '5':
Mystery();
break;
}
}
}
void Sound()
{
Serial.print("Sound");
// while(mode == '1')
{
// if(Serial.available())
{
char mode = Serial.read();
}
int value = analogRead(MIC_PIN);
Serial.println(value);
{
if (value < 120)
{
Serial.print ("SDFGHJKLJHGFDGHJKL:JHGFSDGHKJHGFSDSGHJKHGFSD");
digitalWrite(FLASH_PIN,LOW);
}
else
digitalWrite(FLASH_PIN,HIGH);
}
}
}
void Ultrasonic()
{
// while(mode == '2')
{
// if(Serial.available())
{
char mode = Serial.read();
}
Serial.print("Ultrasonic");
Serial.println(mode);
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM / 2.54); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
Serial.println("in");
if (uS / US_ROUNDTRIP_CM /2.54 < 3) // 12 inch out
{
digitalWrite(FLASH_PIN,LOW); // flash it!
}
else
{
digitalWrite(FLASH_PIN,HIGH); // don't flash it!
}
}
}
void Proximity()
{
// while(mode == '3')
{
// RF disrupter sketch here
Serial.print("Proximity");
Serial.print(mode);
}
}
void Magnetic()
{
// while(mode == '4')
{
// Hall effect sketch
Serial.print("Magnetic");
Serial.print(mode);
}
}
void Mystery()
{
//while(mode == '5')
{
// Jack Bauer special
Serial.print("Mystery");
Serial.print(mode);
}
}