Commit 9005cf80 authored by gujames's avatar gujames
Browse files

Add light signal

parent f18236cc
......@@ -7,6 +7,8 @@ const int echo_pin_mid= 6;
const int trig_pin_right = 5;
const int echo_pin_right = 4;
const int trig_pin_light = 2;
struct Ultrasoundreads {
long data1, data2, data3;
} ultrasound;
......@@ -27,6 +29,9 @@ void setup() {
pinMode(trig_pin_right, OUTPUT);
pinMode(echo_pin_right, INPUT);
// output a light signal when close by
pinMode(trig_pin_light, OUTPUT);
for (int i = 0; i < 19; ++i) {
data[i] = {0, 0, 0};
}
......@@ -110,7 +115,10 @@ double currspeed() {
void loop() {
// reset light signal
digitalWrite(trig_pin_light, LOW);
//array containg read ins from each US
long reads[3];
//read in from US sensors
......@@ -124,11 +132,13 @@ void loop() {
bool check_left = check_against(reads[1], reads[2], reads[0]);
bool check_mid = check_against(reads[0], reads[2], reads[1]);
double time = ((double)reads[1]) / currspeed();
// double time = ((double)reads[1]) / currspeed();
//time > 3 <- value can be set
if ((check_right || check_left || check_mid) && time > 3) {
if ((check_right || check_left || check_mid)) {
// output light signal
digitalWrite(trig_pin_light, HIGH);
Serial.println("There seems to be an object in the way...");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment