HERE IS MY CODE=WHEN I TRY TO COMPLY THE CODE,IT SAY NEW PING DOES NOT A NAME TYPE
OR IT SAID UNQUALIFIED ID.WHAT DOES IT MEAN? ![]()
#include <NewPing.h>
#define pingSpeed 100 //Ping frequency (in milliseconds), fastest we should ping is about 35ms per sensor
NewPing leftUS(3, 2, 30); // Left UltraSonic sensor; trigger pin, echo pin, maximum distance (in cm)
NewPing rightUS(5, 4, 30); //Right UltraSonic sensor; trigger pin, echo pin, maximum distance (in cm)
int leftDistance = 0;
int rightDistance = 0;
int speaker = 8;
boolean PlayNote = false;
unsigned long leftTimer, rightTimer;
void setup() {
//The ping library handles the pinModes for us, so only variable values are entered here. Tone functions also set the speaker as an output
leftTimer = millis() + pingSpeed; // Left sensor will fire at 100ms (pingSpeed)
rightTimer = leftTimer + (pingSpeed / 2); //Right sensor fires 50ms after the left one. This is to avoid the ultrasonic waves interfering with each other
}
void loop() {
getDistance(); //Jump down to the get distance void
int Pitch = map(rightDistance, 0, 30, 131, 247); //Map the distance value to a pitch range (131-247 or C3-B3)
if(leftDistance != 0){ //If we are triggering the left sensor
tone(speaker, Pitch); //Play the note
}
else{
noTone(speaker); //else.. stop playing the note
}
}
void getDistance() {
if (millis() >= leftTimer) { //If we are allowed to fire the left sensor
leftTimer += pingSpeed; //Add the value of the frequency to the timer
leftDistance = leftUS.ping_in(); //Ping and store that distance
}
if (millis() >= rightTimer) {
rightTimer = leftTimer + (pingSpeed / 2);
rightDistance = rightUS.ping_in();
}
}