Go Down

Topic: Compiling problem (Read 2588 times) previous topic - next topic

Hi this is my code :

Code: [Select]
#include <Servo.h>
Servo scanservo;
int lmf = 10;
int lmr = 9;
int rmf = 12;
int rmr = 13;
const int pingpin = 7;
const int scanservopin = 6;
const int turntime = 500;
const int turnaroundtime = 1000;
const int distancelimit = 7;

void setup()
{pinMode(lmf,OUTPUT);
pinMode(lmr,OUTPUT);
pinMode(rmf,OUTPUT);
pinMode(rmr,OUTPUT);
scanservo.attach(scanservopin);
delay(2000);
}
void loop()
{go();
int distance = ping();
if (distance < distancelimit){
  stopmotors();
  char turndirection = scan();
  switch (turndirection){
    case 'l':
    turnleft(turntime);
    break;
    case 'r':
    turnright(turntime);
    break;
    case 's':
    turnleft(turnaroundtime);
    break;
  }
}
}
int ping(){
  long duration, inches, cm;
  pinMode(pingpin,OUTPUT);
  digitalWrite(pinpin,LOW);
  delayMicroseconds(2);
  digitalWrite(pingpin;HIGH);
  delayMicroseconds(5);
  digitalWrite(pingpin,LOW);
  pinMode(pingpin,INPUT);
}
  duration = pulseIn(pingpin,HIGH);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimetres(duration);
}
void go(){
  digitalWrite(rmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,HIGH);
  digitalWrite(lmr,LOW);
}
void turnleft(){
  digitalWrite(rmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(lmr,HIGH);
}
void turnright(){
  digitalWrite(rmf,LOW);
digitalWrite(rmr,HIGH);
digitalWrite(lmf,HIGH);
digitalWrite(lmr,LOW);
}
void stopmotors(){
  digitalWrite(rmf,LOW);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(lmr,LOW);
}
char scan(){
  int leftscanval,centrescanval,rightscanval;
  char choice;
  scanservo.write(30);
  delay(300);
  leftscanval = ping();
  scanservo.write(150);
  delay(1000);
  rightscanval = ping();
  scanservo.write(88);
  centrescanval = ping();
  delay(1000);
  if (leftscanval>rightscanval&&leftscanval>centrescanval){
    choice = 'l';
  }
  else if (rightscanval>leftscanval&&rightscanval>centrescanval){
  choice = 'r';
}
else {
  choice = 's';
}
long microsecondsToInches(long microseconds)
{return microseconds/74/2;
}
long microsecondsToCentimetres(long microseconds){
  return microseconds/29/2;
}



On compiling it shows :
Code: [Select]
"In function 'void loop()':
obstacle_avoiding_bot:7: error: too many arguments to function 'void turnleft()'"


Please help me regarding my
problem.

The code is for an Obstacle Avoiding Bot.


AWOL

#1
Sep 10, 2013, 12:21 pm Last Edit: Sep 10, 2013, 12:23 pm by AWOL Reason: 1
Quote
too many arguments to function

Code: [Select]
void turnleft(){
Code: [Select]
turnleft(turntime);
The function you defined expects no arguments, yet you supplied it with one.
One is more than none, so you get an error.

Code: [Select]
int ping(){
  long duration, inches, cm;
  pinMode(pingpin,OUTPUT);
  digitalWrite(pinpin,LOW);
  delayMicroseconds(2);
  digitalWrite(pingpin;HIGH);
  delayMicroseconds(5);
  digitalWrite(pingpin,LOW);
  pinMode(pingpin,INPUT);
}
  duration = pulseIn(pingpin,HIGH);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimetres(duration);
}

That looks like you've got one too many closing braces "}"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#2
Sep 10, 2013, 12:45 pm Last Edit: Sep 10, 2013, 12:47 pm by firewolf913 Reason: 1
Thanks,
I also get an error which sounds like this:
Code: [Select]
obstacle_avoiding_bot.ino: In function 'int ping()':
obstacle_avoiding_bot:42: error: expected initializer befoore 'pinMode'

AWOL

Quote
I also get an error which sounds like this:

It either "is" or it "isn't" - it doesn't "sound like".

That looks like you've got one too many closing braces "}".
I mentioned this earlier.

Code: [Select]
int ping(){
  long duration, inches, cm;
  pinMode(pingpin,OUTPUT);
  digitalWrite(pinpin,LOW);
  delayMicroseconds(2);
  digitalWrite(pingpin;HIGH);
  delayMicroseconds(5);
  digitalWrite(pingpin,LOW);
  pinMode(pingpin,INPUT);
  return pulseIn(pingpin,HIGH);
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#4
Sep 10, 2013, 01:02 pm Last Edit: Sep 10, 2013, 01:15 pm by firewolf913 Reason: 1
OK,

sorry,

I have just one more error :
Code: [Select]
obstacle_avoiding_bot.ino: In function 'char scan()':
obstacle_avoiding_bot:109: error: a function-definition is not allowed here before '{' token


code :
Code: [Select]
long microsecondsToInches(long microseconds)
 {return microseconds * 0.0133858 / 2;
 }

AWOL

"scan" is missing at least one closing brace, I expect.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Code: [Select]
#include <Servo.h>
Servo scanservo;
int lmf = 10;
int lmr = 9;
int rmf = 12;
int rmr = 13;
const int pingpin = 7;
const int scanservopin = 6;
const int turntime = 500;
const int turnaroundtime = 1000;
const int distancelimit = 5;

void setup()
{pinMode(lmf,OUTPUT);
pinMode(lmr,OUTPUT);
pinMode(rmf,OUTPUT);
pinMode(rmr,OUTPUT);
scanservo.attach(scanservopin);
delay(2000);
}
void loop()
{go();
int distance = ping();
if (distance <= distancelimit){
  stopmotors();
  char turndirection = scan();
  switch (turndirection){
    case 'l':
    turnleft;
    break;
    case 'r':
    turnright;
    break;
    case 's':
    turnaround;
    break;
  }
}
}
int ping(){
  long duration, inches, cm;
  pinMode(pingpin,OUTPUT);
  digitalWrite(pingpin,LOW);
  delayMicroseconds(2);
  digitalWrite(pingpin,HIGH);
  delayMicroseconds(5);
  digitalWrite(pingpin,LOW);
  pinMode(pingpin,INPUT);
  duration = pulseIn(pingpin,HIGH);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimetres(duration);
}
void go(){
  digitalWrite(rmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,HIGH);
  digitalWrite(lmr,LOW);
}
void turnleft(){
  digitalWrite(rmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(lmr,HIGH);
  delay (500);
}
void turnright(){
  digitalWrite(rmf,LOW);
digitalWrite(rmr,HIGH);
digitalWrite(lmf,HIGH);
digitalWrite(lmr,LOW);
delay (500);
}
void stopmotors(){
  digitalWrite(rmf,LOW);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(lmr,LOW);
}
void turnaround(){
  digitalWrite(rmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(lmr,HIGH);
  delay(1000);
}
char scan(){
  int leftscanval,centrescanval,rightscanval;
  char choice;
  scanservo.write(30);
  delay(300);
  leftscanval = ping();
  scanservo.write(150);
  delay(1000);
  rightscanval = ping();
  scanservo.write(88);
  centrescanval = ping();
  delay(1000);
  if (leftscanval>rightscanval&&leftscanval>centrescanval){
    choice = 'l';
  }
  else if (rightscanval>leftscanval&&rightscanval>centrescanval){
  choice = 'r';
}
else {
  choice = 's';
}

long microsecondsToInches(long microseconds)
  {return microseconds * 0.0133858 / 2;
  }
long microsecondsToCentimetres(long microseconds){
  return microseconds * 0.0343 / 2;
}

AWOL

#7
Sep 10, 2013, 01:40 pm Last Edit: Sep 10, 2013, 01:47 pm by AWOL Reason: 1
Code: [Select]
int ping(){
 long duration, inches, cm;
 pinMode(pingpin,OUTPUT);
 digitalWrite(pingpin,LOW);
 delayMicroseconds(2);
 digitalWrite(pingpin,HIGH);
 delayMicroseconds(5);
 digitalWrite(pingpin,LOW);
 pinMode(pingpin,INPUT);
 duration = pulseIn(pingpin,HIGH);
 inches = microsecondsToInches(duration);
 cm = microsecondsToCentimetres(duration);
}

You've got a bit of a problem here; you've promised the compiler that you're going to return an "int", and then you don't do it.
Shame on you.

It still looks like "scan" is missing one or more closing braces.


Code: [Select]
(rightscanval>leftscanval&&rightscanval>centrescanval)
Istheresomethingwrongwithyourspacekey?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Go Up