[solved]Servo program won't compile
hi there folks,
i'm trying make device maker faire, got completed program has 1 mistake has attaching writing of servo. it's supposed point @ strongest lightsource through 2 ldrs, turning servo. down below code got it. problem quite obvious can't seem figure out. take @ , explain me i'm doing wrong?
it gives following error:
thanks have answer.
i'm trying make device maker faire, got completed program has 1 mistake has attaching writing of servo. it's supposed point @ strongest lightsource through 2 ldrs, turning servo. down below code got it. problem quite obvious can't seem figure out. take @ , explain me i'm doing wrong?
code: [select]
#include <servo.h>
#define servo 9
#define leftsensor 0
#define rightsensor 1
#define button 2
#define led 13
servo servo;
int speed = 50;
int leftsensorval = 0;
int rightsensorval = 0;
int sensorthreshold = 200;
int delayparam = 10;
int buttonval = 0;
int old_buttonval = 0;
int buttonstate = 0;
void setup()
{
serial.begin(9600);
servosetup();
}
void loop()
{
leftsensorval = analogread(leftsensor);
rightsensorval = analogread(rightsensor);
buttonval = digitalread(button);
if((buttonval == high) && (old_buttonval == low))
{
serial.println("button pushed");
buttonstate = 1 - buttonstate;
delay(10);
}
old_buttonval = buttonval;
if(buttonstate == 1)
{
digitalwrite(led, high);
if(leftsensorval - rightsensorval >= sensorthreshold)
{
serial.println("left");
goleft();
delay(delayparam * 100);
gostop();
}
else if(rightsensorval - leftsensorval >= sensorthreshold)
{
serial.println("right");
goright();
delay(delayparam * 100);
gostop();
}
}
else
{
serial.println("stop");
digitalwrite(led, low);
gostop();
}
}
void servosetup()
{
setspeed(speed);
pinmode(servo, output);
servo.attach(servo);
pinmode(button, input);
pinmode(led, output);
gostop();
}
void setspeed(int newspeed)
{
setspeedservo(newspeed);
}
void setspeedservo(int newspeed)
{
if(newspeed >= 100) {newspeed = 100;}
if(newspeed <= 0) {newspeed = 0;}
speed = newspeed * 0.9;
}
void goright()
{
servo.write(90 + speed);
}
void goleft()
{
servo.write(90 - speed);
}
void gostop()
{
servo.write(90);
}
it gives following error:
quote
sketch_may25a.ino:2:15: error: expected unqualified-id before numeric constant
sketch_may25a.ino:8:7: note: in expansion of macro 'servo'
sketch_may25a.ino: in function 'void servosetup()':
sketch_may25a.ino:70:9: error: request member 'attach' in '9', of non-class type 'int'
sketch_may25a.ino: in function 'void goright()':
sketch_may25a.ino:90:9: error: request member 'write' in '9', of non-class type 'int'
sketch_may25a.ino: in function 'void goleft()':
sketch_may25a.ino:95:9: error: request member 'write' in '9', of non-class type 'int'
sketch_may25a.ino: in function 'void gostop()':
sketch_may25a.ino:100:9: error: request member 'write' in '9', of non-class type 'int'
thanks have answer.
hi lenny
you've confused poor program
the first "servo" represents pin number. the second servo name of instance of servo object. one of "servo"s needs change. probably quicker change former, , remember change wherever pin number appears parameter function call. example ...
regards
ray
code: [select]
#define servo 9
...
servo servo;
you've confused poor program
the first "servo" represents pin number. the second servo name of instance of servo object. one of "servo"s needs change. probably quicker change former, , remember change wherever pin number appears parameter function call. example ...
code: [select]
#define servopin 9
regards
ray
Arduino Forum > Using Arduino > Programming Questions > [solved]Servo program won't compile
arduino
Comments
Post a Comment