Go Down

Topic: serial communication (Read 370 times) previous topic - next topic

theodosis

the following is the code i have wrote.
when i press the compilling button seems something goes wrong ...

#include <AFMotor.h>

AF_DCMotor motor1(3, MOTOR12_64KHZ);
AF_DCMotor motor2(4, MOTOR12_64KHZ);
char val;

void setup()
{
   Serial.begin(9600);    
  motor1.setSpeed(255);   
  motor2.setSpeed(255);
}
void go_forward()
{
  motor1.run(FORWARD);
  motor2.run(FORWARD);   
}
void go_reverse()
{
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
}
void go_left()
{
  motor1.run(FORWARD);
  motor2.run(BACKWARD);
}
void go_right()
{
  motor1.run(BACKWARD);
  motor2.run(FORWARD);
}
void stop_all action()
{
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}
void loop()
{
  if(Serial.available())
  {
    val = Serial.read();
 
  if (val == 'f')
  {
      go_forward();
    }
    else if (val == 's')
    {
      stop_all action();
    }
    else if (val == 'b')
    {
      go_reverse();
    }
    else if (val == 'r')
    {
      go_right();
    }
    else if (val == 'l')
    {
      go_left();
    }
  }
}
the errors i get are the following,but why?

"sketch_sep05d:33: error: expected initializer before 'action'
sketch_sep05d.ino: In function 'void loop()':
sketch_sep05d:50: error: 'stop_all' was not declared in this scope
sketch_sep05d:50: error: expected `;' before 'action' "
PLEASE HELP!!


AWOL

You can't have spaces in a variable or function name.

Please remember to use code tags when posting code.
"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.

Graynomad

stop_all action();

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy