ive had a look at the megaservo code and it dosen’t mean anything to me.
im getting lost could someone send me a code with some comments on it to get me started
ive had a look at the megaservo code and it dosen’t mean anything to me. im getting lost could someone send me a code with some comments on it to get me started
The MegaServo playground write-up has a link to the Arduino Servo reference information at the top of the article. This documents the functions and has example code. did you have a look at that?
sorry to confuse things but this is the code i would like come comments on
MegaServo Servos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards
int pos = 0; // variable to store the servo position
int potPin = 0; // connect a pot to this pin.
void setup()
{
for( int i =0; i < NBR_SERVOS; i++)
Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200);
}
void loop()
{
pos = analogRead(potPin); // read a value from 0 to 1023
for( int i =0; i <NBR_SERVOS; i++)
Servos[i].write( map(pos, 0,1023,0,180));
delay(15);
}
I have downloaded the megaservo from the arduino website.
I have also copied and pasted the reply code from BillHo into the file but im now getting an error message when i upload to my board.
can you please explain where im going wrong
23: error: MegaServo.h: No such file or directory In function ‘void setup()’:
In function ‘void loop()’:
Jason, is MegaServo copied into the Arduino Library directory? From the Arduino IDE menu, select Sketch / ImportLibrary - can you see MegaServo in the list of libraries?
im using the megaservo library and this is my code but it seems to be a bit jittery am i doing something wrong or could the code be written in a different way.
my aim is to control 4 servos to run a model railway digger.
Jason, the current needed depends on the servo and the load but 500ma is probably not enough. Perhaps I can say more if I knew what servos are you using and what kind of load each servo has, but I would test with a 1.5amps or more if you can.
BTW, your code keeps attaching pin 10 in loop – it is better if you move that line into setup.
can you please explain what you mean. and can you correct my code so that it is correct because at the moment im still playing and i still don’t under stand it all yet
BTW, your code keeps attaching pin 10 in loop – it is better if you move that line into setup.
I think what mem is saying is that you only need to attach the servos to the pins once so that should be done in the setup function.
Currently only the “digger” servo is attached in the setup function. By attaching the up and down servos in your main loop, it is attaching them each time through the loop and this may cause some jittering. Your setup function should look something like this: