Pages: [1]   Go Down
Author Topic: Compiling problem  (Read 2303 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi this is my code :

Code:
#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:
"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.

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
too many arguments to function
Code:
void turnleft(){
Code:
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:
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 "}"
« Last Edit: September 10, 2013, 05:23:53 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,
I also get an error which sounds like this:
Code:
obstacle_avoiding_bot.ino: In function ‘int ping()’:
obstacle_avoiding_bot:42: error: expected initializer befoore ‘pinMode’
« Last Edit: September 10, 2013, 05:47:44 am by firewolf913 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK,

sorry,

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

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


* Screenshot from 2013-09-10 16:46:20.png (27.23 KB, 500x600 - viewed 47 times.)
« Last Edit: September 10, 2013, 06:15:24 am by firewolf913 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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;
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
(rightscanval>leftscanval&&rightscanval>centrescanval)
Istheresomethingwrongwithyourspacekey?
« Last Edit: September 10, 2013, 06:47:34 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much smiley
Logged

Pages: [1]   Go Up
Jump to: