Hi,
First of all THANK YOU TIM for this library!!!!!!!!!!!!!!!!!!!!
And thank you to all the enthusiasts who have been posting here!
I have been running into a slight problem that I have not been able to fix, despite dowloading the lib again, googling it a million times, etc. I am trying to get readings from a PING))) sensor and from a maxbotic MAX SONAR (which can be PWM, An or BW, I have it as PWM) and arduino throws the same error:
'NewPing' does not name a type
sketch_jan06a:3: error: 'NewPing' does not name a type
sketch_jan06a:4: error: 'NewPing' does not name a type
sketch_jan06a.cpp: In function 'void loop()':
sketch_jan06a:19: error: 'sonar1' was not declared in this scope
sketch_jan06a:23: error: 'sonar2' was not declared in this scope
The code I used is the modified sample one provided:
#include <NewPing.h>
//barely modified sketch from Tim Eckel's original sketch
NewPing sonar1(11, 12, 200); // Sensor 1: trigger pin, echo pin, maximum distance in cm
NewPing sonar2(9, 10, 200); // Sensor 2: same stuff
#define pingSpeed 100 // Ping frequency (in milliseconds), fastest we should ping is about 35ms per sensor
unsigned long pingTimer1, pingTimer2;
void setup() {
Serial.begin(9600);
// Do other stuff here
pingTimer1 = millis() + pingSpeed; // Sensor 1 fires after 100ms (pingSpeed)
pingTimer2 = pingTimer1 + (pingSpeed / 2); // Sensor 2 fires 50ms later
}
void loop() {
if (millis() >= pingTimer1) {
pingTimer1 += pingSpeed; // Make sensor 1 fire again 100ms later (pingSpeed)
int in1 = sonar1.ping_in();
}
if (millis() >= pingTimer2) {
pingTimer2 = pingTimer1 + (pingSpeed / 2); // Make sensor 2 fire again 50ms after sensor 1 fires
int in2 = sonar2.ping_in();
// Both sensors pinged, process results here
}
// Do other stuff here, notice how there's no delays in this sketch, so you have processing cycles to do other things :)
}
Any suggestions would be greatly greatly appreciated..... Thank you!!!!!