Can you help my Arduino code problem?
#include <Servo.h>
#define LEFTSERVOPIN 10
#define RIGHTSERVOPN 9
Servo leftServo;
Servo rightServo;
int speed = 100;
int pc1_pin = 0;
int pc2_pin = 1;
int pos = 90;
void setup()
int speed = 100;
pinMode(LEFTSERVOPIN, OUTPUT);
pinMode(RIGHTSERVOPIN, OUTPUT);
leftServo.attach(LEFTSERVOPIN);
rightServo.attach(RIGHTSERVOPIN);
goStop();
}
void loop()
{
if ( analogRead(pc2_pin)) < 50 - analogRead(pc1_pin)) > 50 );
void goRight()
{
leftServo.write(90 - speed)
rightServo.write(speed)
}
if ( analogRead(pc2_pin)) > 50 - analogRead(pc1_pin)) < 50 );
{
void goLeft()
leftServo.write(speed)
rightServo.write(90 - speed)
}
if else{leftServo.write(speed); rightServo.write(speed);}
}
but it won't work for the following reasons,
unfinished_light_follow.cpp: In function 'void setup()':unfinished_light_follow:15: error: 'RIGHTSERVOPIN' was not declared in this scope
unfinished_light_follow:18: error: 'goStop' was not declared in this scopeunfinished_light_follow:23: error: a function-definition is not allowed here before '{' token
unfinished_light_follow:40: error: expected `}' at end of input
9
answers
|
Answer it!
|
It is difficult for us to explain all of the rather poor messages and what they might mean the *real* problem is. To help you learn how to do this for yourself I've debugged your code starting from your first posting. I show you the error messages I got and what changes I had to implement to fix each one. Look over this text file to help you learn how to fix future problems.
Best Wishes
unfinished_light_follow.cpp: In function 'void setup()':
unfinished_light_follow:13: error: 'RIGHTSERVOPIN' was not declared in this scope
unfinished_light_follow:16: error: 'goStop' was not declared in this scope
unfinished_light_follow.cpp: At global scope:
unfinished_light_follow:21: error: expected initializer before 'if'
unfinished_light_follow:22: error: expected unqualified-id before '{' token
You mis-spelt RIGHTSERVOPIN in the declaration of it !
Steve
unfinished_light_follow:16: error: 'goStop' was not declared in this scope
unfinished_light_follow.cpp: At global scope:
unfinished_light_follow:21: error: expected initializer before 'if'
unfinished_light_follow:22: error: expected unqualified-id before '{' token
Just look REALLY hard at what you've written, and try and format your code much better.
#include <Servo.h>
#define LEFTSERVOPIN 10
#define RIGHTSERVOPN 9
Servo leftServo;
Servo rightServo;
int speed = 100;int pc1_pin = 0;
int pc2_pin = 1;
int pos = 90;
void setup()
{
int speed = 100;
pinMode(LEFTSERVOPIN, OUTPUT);
pinMode(RIGHTSERVOPIN, OUTPUT);
leftServo.attach(LEFTSERVOPIN);
rightServo.attach(RIGHTSERVOPIN);
// goStop(); <<<<Not defined in routine
}
void loop()
{
if ( analogRead(pc2_pin)) < 50 - analogRead(pc1_pin)) > 50 );
//void <<<why here ?
/// goRight() <<<<<What's this ? ?
{leftServo.write(90 - speed)
rightServo.write(speed)
}
if ( analogRead(pc2_pin)) > 50 - analogRead(pc1_pin)) < 50 );
{
void goLeft()
leftServo.write(speed)
rightServo.write(90 - speed)
}
if else{leftServo.write(speed); rightServo.write(speed);}
}
Its ALWAYS a good idea to take other people's code to pieces and understand the syntax.
![]() |


































