diff --git a/proximityAlarm.ino b/proximityAlarm.ino new file mode 100644 index 0000000..19a9183 --- /dev/null +++ b/proximityAlarm.ino @@ -0,0 +1,108 @@ +/* + Inspectio + + Detects objects on the left and right of a person wearing the belt and signals them + when objects are close by + + circuit: + - 1, 8 ohm speaker on digital pin 8 + - #, ultrasonic sensors + + created 20 Oct 2019 + by Blue Wall Peeps + + https://github.com/CSBar/HackUMass19 +*/ +// program parameters +const int minDistance = 70; //farthest object distance that will trigger a beep +const int numOfSensors = 2; //number of functional sensors connected + +typedef struct sensor { + int trigPin; + int echoPin; +} sensor; + +// defines pin numbers +const sensor sensorList[numOfSensors] = {{8, 7}, {3,2}}; +const int buzzer = 13; + +enum direction { + LEFT, + RIGHT +}; + + +/* + * Has the specified sensor scan for nearby objects + * @param ultrasonicSensor - specified sensor with valid trigPin and echoPin connected to arduino + * @return distance (in cm) of the nearest object detected by the sensor +*/ +int detectNearestObject(sensor ultrasonicSensor); + +/* + * Sends a signal to the speaker to play specified sounds + * Discriminates left and right sensor signals and sounds more frequently when objects are closer to the sensor + * @param direction - whether the sensor sending a signal is from the left or right side of the person + * @param distance - distance (in cm) of the nearest object detected by the sensor + * @return NOTHING +*/ +void playBuzzerSound(int direction, int distance); + + +void setup() { + for(int i=0; i