Go Down

Topic: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7 (Read 644004 times) previous topic - next topic

MuhammadMohtashim

Hello, I am looking for a way to use 4 sensors with this code. Which it superbly does. It's an amazing piece of code. But I am looking to average the readings from the 4 sensors. My problem is the last bit of code

for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm);
    Serial.print("cm ");
  }

Just pushes the readings in four separate ways. How can I take the readings from the 4 sensors and get their average and put out on the screen?

Thank you.

TheMemberFormerlyKnownAsAWOL

Add them all together and divide by four.

Please remember to use code tags when posting code
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

thatimetat

What sense does it make for return type of ping_median() to be unsigned long when the array uS[it] is of type unsigned int?

juanjnd


MuhammadMohtashim

Add them all together and divide by four.

Please remember to use code tags when posting code
Yes..But how?

worked with 2 sensors. Tried adding cm[0] and cm[1] together but the values I get are bigger. For example if the sensor 1 is 9cm so cm[0] should also be 9cm but it is 90cm.

I created a new array "fyp' and used memcpy to copy the cm array into it but only the cm[0] gets copied to  fpy[0] and fyp[1] is 0cm even when cm[1] gives 10cm

TheMemberFormerlyKnownAsAWOL

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Go Up