Hi,
a question about NewPing again, the example of NewPing3Sensors_ls from NewPing defined NewPing sonar[SONAR_NUM] and NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); in NewPingTimerMedian_M.
How can I use them the way below?
Please let me know If need I'll upload the examples.
Thanks
Adam
// ---------------------------------------------------------------------------
// Example NewPing library sketch that pings 3 sensors 20 times a second.
// ---------------------------------------------------------------------------
#include <NewPing.h>
#define SONAR_NUM 3 // Number of sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
NewPing sonar[SONAR_NUM] = { // Sensor object array.
NewPing(4, 5, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
NewPing(6, 7, MAX_DISTANCE),
NewPing(8, 9, MAX_DISTANCE)
};
float duration, distance;
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop() {
for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through each sensor and display results.
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print(i);
Serial.print("=");
Serial.print(sonar[i].ping_cm());
Serial.print("cm ");
}
Serial.println();
duration = sonar.ping_median(iterations);
}
ERROR:
Arduino: 1.8.3 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\HUA.DELLV-PC\Documents\Arduino\NewPing3Sensors_ls\NewPing3Sensors_ls.ino: In function 'void loop()':
NewPing3Sensors_ls:32: error: request for member 'ping_median' in 'sonar', which is of non-class type 'NewPing [3]'
duration = sonar.ping_median(iterations);
^
NewPing3Sensors_ls:32: error: 'iterations' was not declared in this scope
duration = sonar.ping_median(iterations);
^
exit status 1
request for member 'ping_median' in 'sonar', which is of non-class type 'NewPing [3]'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
