'class SharpIR'has no member named 'distance'

hello,i'm facing problem while coding this.can someone help me?when i want to upload it,it's keep telling me that 'class SharpIR' has no member named 'distance'.How can i get out from this :slight_smile:
This is my code:

//define sensor
#define RIGHT A0
#define FRONT A2
#define LEFT A7

SharpIR SharpIR_1 (RIGHT,1080);
SharpIR SharpIR_3 (FRONT,430);
SharpIR SharpIR_5 (LEFT,1080);

int IN1 = 7;
int IN2 = 6;
int IN3 = 5;
int IN4 = 4;

void setup() {
// put your setup code here, to run once:

delay(3100);

Serial.begin(9600);
Serial.print("START");

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

pinMode(13 , OUTPUT);

}

void loop() {

const int dis1=SharpIR_1.distance();
const int dis3=SharpIR_3.distance();
const int dis5=SharpIR_5.distance();

if(dis5 < 20)
{
Serial.println("FRONT");
Serial.println(dis3);

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);

}

else if(dis1 < 35)
{
Serial.println("RIGHT");
Serial.println(dis1);

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

else if(dis3 < 35)
{
Serial.println("LEFT");
Serial.println(dis5);

digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
else {

digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);

}
}

Hi aqrix, welcome to the community.

For ease of those who are trying to help please put your code in code tags see </> on the edit window ribbon. It makes it much easier to view your code. And before you post your code, in the IDE under the tools menu the top option is format. Please apply this to your code before posting. Again it enhances readability.

Hi,
when registering as a new user in the forum, did you read the topic
" How to get the best out of this forum "?
If you haven't read it, I recommend you do!
If you read it, you must have understood that to post code you must use the </> tags.
I recommend that you edit your topic and put it in tags.

This library you are using does not have a distance() method
used in other lines like this "
const int dis1=SharpIR_1.distance(); //RIGHT"

correct all lines for getDistance() and see if it works.

const int dis1=SharpIR_1.getDistance(); //RIGHT"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.