3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Can you help my Arduino code problem?

this is my code for a light following robot it is driven by two modified servos.
#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
sort by: active | newest | oldest
Jan 10, 2011. 2:57 PMmaewert says:
DaveTheAwesome,

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
Jan 8, 2011. 3:32 PMsteveastrouk says:
Missing { in setup for a start.
Jan 8, 2011. 4:09 PMsteveastrouk says:
I don't know if the Ibles site strips your formatting, but it is always good style to indent your code properly, to make it easier to read. The closing brace was also missing in your setup() command.

You mis-spelt RIGHTSERVOPIN in the declaration of it !

Steve
Jan 9, 2011. 3:29 AMsteveastrouk says:
You're not being annoying, but you are short-circuiting a vital part of learning any programming language - working out what the arcane, dumb and unhelpful error messages mean. I have to say Arduino's error messages are particularly badly done.

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.


Jan 8, 2011. 5:25 PMfrollard says:
you're also declaring a void within an if statement.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!