void value not ignored as it ought to be in the Arduino IDE(a ROBOT )

Hello everybody!

I’m a programming a my Robot car automatic mode, but why i’m compiled the program I see a the IDE error… I’m using a Arduino UNO

“carrorobo.ino: In function ‘void decision)’:
carrorobo.ino:142:13: error: void value not ignored as it ought to be”

Can we help me?

The code :

int distance_left;
int distancia_right;

#include <Servo.h>

Servo myservo;

#define motor1A 4
#define motor2A 5

#define motor1B 6
#define motor2B 7

#include “Ultrasonic.h”
// Portas do Arduino que vou utilizar para programar o sensor

Ultrasonic ultrasonic(12,13);

int distance;

void setup ()
{
Serial.print(“Lendo dados dos sensores:”);
Serial.begin(9600);

pinMode(motor1A,OUTPUT);
pinMode(motor2A,OUTPUT);

pinMode(motor1B,OUTPUT);
pinMode(motor2B,OUTPUT);

myservo.attach(8);

myservo.write(80);
delay(500);

}

void loop () {

watching();

ahead();

if (distance < 12)
{
decision();

}
}

void ahead () {

digitalWrite(motor1A,LOW);
digitalWrite(motor2A,HIGH);
digitalWrite(motor1B,LOW);
digitalWrite(motor2B,HIGH);

}

void back(){

digitalWrite(motor1A,HIGH);
digitalWrite(motor2A,LOW);
digitalWrite(motor1B,LOW);
digitalWrite(motor2B,HIGH);

}

void right(){

digitalWrite(motor1A,HIGH);
digitalWrite(motor2A,LOW);
digitalWrite(motor1B,HIGH);
digitalWrite(motor2B,LOW);
}

void left () {

digitalWrite(motor1A,LOW);
digitalWrite(motor2A,LOW);
digitalWrite(motor1B,HIGH);
digitalWrite(motor2B,HIGH);

}

void stop () {

digitalWrite(motor1A,LOW);
digitalWrite(motor2A,LOW);
digitalWrite(motor1B,LOW);
digitalWrite(motor2B,LOW);

}

void returned_right(){

parado();
delay(1000);
direita();
delay(1000);
frente();
}

void wathcing(){

// Funçao para Fazer leituras de Sensor Ultrasonico
distance = (ultrasonic.Ranging(CM));

Serial.print(distance);
Serial.println(“cm de distancia”);
delay(500);

}

void decision() {
stop();
delay(500);
myservo.write(0);
delay(500);

distance_right = wathcing();
delay(2000);
myservo.write(175);
delay(500);

// distance_left = busca();
delay(2000);
myservo.write(80);
delay(500);

if(distance_right > distance_left)
{
back();
delay(600);
right();
delay(2000);
ahead();

}

else
{
back();
delay(600);
left();
delay(2000);
ahead();

}

}

Help me , thanks :slight_smile:

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code looklike thiswhen posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button.

distance_right = wathcing();

you want distance_right to be equal to the return value from wathcing

BUT

void wathcing(){

wathcing is defined to return void. That is, it doesn't return any value.

So what from wathcing() do you want distance_right to be set to?

watching() should NOT be setting a global variable. It should return a value that you can assign to a variable.

Your coding style is awful. There are two schools of thought as to where the curly braces go. Some like:

void fun() {
   // code
}

The smarter ones prefer:

void fun()
{
   // code
}

The argument made in favor of putting the { on the line with the function is that it uses fewer lines overall. Your style blows that argument clean out of the water with white space immediately following EVERY place where the { is on the same line as the function/statement that defines the block.