HELP ON! ERROR: void value not ignored as it ought to be

Hi, so I am trying to create a code for a quadruped robot(dog like); I am building the code one by one, I am creating a test program with sensor, which basically this code below shows, my problem is that i got the error: void value not ignored as it ought to be, the error code is on red color. I do not know if it is valid to do " leftdistance = ping(); ".

Please help me… :frowning:
I am using 1.0.4
Ultrasonic US-100 Sensor
16-channel Servo Controller
Gizduino X ATmega 1281

-------------------------CODE HERE--------------------------------------

#include <NewPing.h>
#include <Servo.h>

#define TRIGGER_PIN 6 //SENSOR
#define ECHO_PIN 7
#define MAX_DISTANCE 200

#define FLHcenter 1550 //HIP SERVO
#define FRHcenter 1350
#define BLHcenter 1550
#define BRHcenter 1500

Servo FRHservo;
Servo FLHservo;
Servo BLHservo;
Servo BRHservo;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int DistanceCm;
int DistanceIn;
int distance = 0;
char movement;
char test =β€˜R’;
int leftdistance[1];
int rightdistance[1];

void setup(){
FRHservo.attach(0);
FLHservo.attach(8);
BLHservo.attach(1);
BRHservo.attach(9);

FLHservo.writeMicroseconds(FLHcenter); // Center servos
FRHservo.writeMicroseconds(FRHcenter);
BRHservo.writeMicroseconds(BRHcenter);
BLHservo.writeMicroseconds(BLHcenter);

Serial.begin(9600);
}

void loop(){
int test;
tuloyangbuhay();
if(DistanceCm >= distance+50){
if(test == β€˜L’){
leftdistance = ping();
test = β€˜R’;
}
else{
rightdistance = ping();
test = β€˜L’;
}
}

}
void FRH(){
Serial.write(0x02); //FRH
Serial.print(β€œ0,900,30”);
Serial.write(0x03);
delay(1500);

Serial.write(0x02);
Serial.print(β€œ0,2500,30”);
Serial.write(0x03);
delay(1500);
}

void FLH(){
Serial.write(0x02); //FLH
Serial.print(β€œ8,900,30”);
Serial.write(0x03);
delay(1500);

Serial.write(0x02);
Serial.print(β€œ8,2500,30”);
Serial.write(0x03);
delay(1500);
}

void BRH(){
Serial.write(0x02); //BRH
Serial.print(β€œ1,900,30”);
Serial.write(0x03);
delay(1500);

Serial.write(0x02);
Serial.print(β€œ1,2500,30”);
Serial.write(0x03);
delay(1500);
}

void tuloyangbuhay(){
FRH();
FLH();
BRH();
BLH();
}

void BLH(){
Serial.write(0x02); //BLH
Serial.print(β€œ9,900,30”);
Serial.write(0x03);
delay(1500);

Serial.write(0x02);
Serial.print(β€œ9,2500,30”);
Serial.write(0x03);
delay(1500);
}

void ping(){
delay(100);
DistanceIn = sonar.ping_in();
Serial.print("Ping: β€œ);
Serial.print(DistanceIn);
Serial.print(” in ");
delay(1000);
DistanceCm = sonar.ping_cm();
Serial.print(β€œPing: β€œ);
Serial.print(DistanceCm);
Serial.println(” cm”);
}

You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :slight_smile:

Edit:

I do not know if it is valid to do " leftdistance = ping(); ".

No, it's not. 'ping()' doesn't return a value.

And in 'ping()' maybe it would be a good idea to decide if you want to work in inches or centimeters, then delete the unused function call and related serial prints.

Add code tags as suggested and we can more easily help you further. There are a few things that need addressing in your code.

If you want ping() to return a value, then you need to change the return type from void to something else and figure out what you want to return and include a return statement.

But since DistanceCm is a global variable there is no need to return anything. Just call ping() and it puts the distance in there.

also this is not right:

int leftdistance[1];

An array with only one element is pretty useless. You should just make it a variable and drop the array part if you only need one of them.

int leftdistance;

Please use code tags.

Read this before posting a programming question

How to use this forum

void tuloyangbuhay(){

FRH();
Β  FLH();
Β  BRH();
Β  BLH();
}

We decided to throw documentation and readability right out of the window, right?