Skip to content

Commit

Permalink
Update maxbotix.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Praneethsvch authored Apr 7, 2021
1 parent 2b1159f commit 466827f
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/maxbotix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ void setup_maxbotix(unsigned int mode=2, unsigned int sampling_rate=250 , unsign
digitalWrite(triggerPin, LOW);
Serial1.begin(9600);
Serial.println("Sensor Settings:");
writeToSDCard(String("Sensor Settings:"));
sensorMode = mode;
Serial.print(" Sensor mode: ");
Serial.println(sensorMode);
writeToSDCard(String(" Sensor mode: "+ sensorMode));
sensor_sampling_rate = sampling_rate;
Serial.print(" Sensor sampling rate: ");
Serial.println(sensor_sampling_rate);
writeToSDCard(String(" Sensor sampling rate: "+ sensor_sampling_rate));
sensor_numberOfReadings = numberOfReadings;
Serial.print(" Number of readings per measurement: ");
Serial.println(sensor_numberOfReadings);
writeToSDCard(String(" Number of readings per measurement: "+ sensor_numberOfReadings));
}

uint16_t sensor_singleread(void) {
Expand Down Expand Up @@ -85,34 +81,25 @@ uint16_t read_sensor_using_modes(unsigned int sensorMode, unsigned int sensor_sa
}
Serial.println("");
writeToSDCard(readings_array_string);
readings_array_string = ""; //Cleaning readings array string

switch (sensorMode) {
case 1:
// Mean
distance = mean(readings_arr, n, sensor_numberOfReadings);
Serial.print("Mean is: "); Serial.println(distance);
readings_array_string = String("Mean is: " + distance);
writeToSDCard(readings_array_string);
break;
case 2:
// Median
distance = median(readings_arr, n, sensor_numberOfReadings);
Serial.print("Median is: "); Serial.println(distance);
readings_array_string = String("Median is: " + distance);
writeToSDCard(readings_array_string);
break;
case 3:
// Mode
distance = mode(readings_arr, n, sensor_numberOfReadings);
Serial.print("Mode is: "); Serial.println(distance);
readings_array_string = String("Mode is: " + distance);
writeToSDCard(readings_array_string);
break;
default:
// Single Pulse-In single reading
distance = sensor_singleread();
Serial.print("Default single reading is: "); Serial.println(distance);
readings_array_string = String("Default single reading is: " + distance);
writeToSDCard(readings_array_string);
break;
}
Serial.println("Cleaning measurements array...");
writeToSDCard(String("Cleaning measurements array..."));
Expand Down

0 comments on commit 466827f

Please sign in to comment.