Pages: [1]   Go Down
Author Topic: serial communication  (Read 228 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!

Logged

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

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

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

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 121
Posts: 8442
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

stop_all action();

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: