My Computer Science teacher did some wizardry on this code and he never explained the values and variables used in the area of the code from void loop to delay when I asked.
This code I have attached is for calculating the distance detected by a (waterproof) ultrasonic distance sensor. The code is written to output a voltage to vibration motors (which are connected to pins on the arduino uno board). The code (once upon a time) enabled the vibration motors to vibrate on a nice fluid and smooth spectrum as the distance changed. (Stronger vibration closer, weaker vibration further).
Now though, I try recompiling the exact code I have attached here, but I get the same error that states getDistance() is not declared. Could someone please inform me on how to correct this error? I am willing to except any help.
I do not think it is a bootloader issue, I just have a minor error in my code that I keeping failing at correcting. I will try to upload my code on code tags. Only an arduino uno, vibration motor, and sensor was used (besides other functionality basics). Thanks for your reply.
This code won't compile because you haven't defined any function named getDistance() yet used it in void loop() .
You have submitted us an image since you are new am doing it but take lesson for next time.
const int echoPin=12;
const int trigPin=11;
const int motorPin=3;
float distance=0;
void setup(){
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(motorPin,OUTPUT);
}
void loop(){
distance=distance*.9+.1*getDistance();
Serial.print(distance);
Serial.println(" in");
if(distance >10 && distance <100){
float p=(distance-10)/(100-10);
int v=(int)(255*(1-p)+50*p);
analogWrite(motorPin,v);
}
else{
analogWrite(motorPin,0);
}
delay(50);
}
Here I am adding the function below and modifying the line a little .Just copy paste this code and it should work.