Go Down

Topic: serial communication (Read 322 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
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview