my project is to store the data generated by ultrasonic sensor in an array (atleast 3 different values) and then find the median of those values. I have written a code for storing the values in array but unable to find the median.
Also please check the code for array
const int trigPin = 3;
const int echoPin = 2;
long duration,distance,Sensor;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
distance = calculateDistance();
int i=0;
int dist = {distance};
- for(i=0;i<3;i++)*
- {*
_ Serial.println(dist*);_
_ return 1;_
_ }_
_}_
int calculateDistance()
_{_
_ digitalWrite(trigPin, LOW);_
_ delayMicroseconds(2);_
_ digitalWrite(trigPin, HIGH);_
_ delayMicroseconds(10);_
_ digitalWrite(trigPin, LOW);_
_ duration = pulseIn(echoPin, HIGH);_
_ distance = (duration/2)0.034;_
_}_
ultra_sonic.ino (622 Bytes)