Concerning the 16 Channel 12C and servo controlling example code

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
bent2
 
Posts: 1
Joined: Sat Apr 20, 2013 10:37 pm

Concerning the 16 Channel 12C and servo controlling example code

Post by bent2 »

My first project with Arduino is here:
http://www.youtube.com/watch?v=qraGT4k5 ... oA&index=1

But my question is I always see when controlling the servos code like this:
for(uint16 i = 0; i < position; i++){
pwm.setPWM(15, 0, position);
}

this is to drive the servo 15 from 0 to position but I noticed that I can always just write:
pwm.setPWM(15, 0, position);

And it will move from wherever it happens to be to position.

Like the servo sweep example becomes just:
pwm.setPWM(15,0,SERVOMIN);
delay(500);
pwm.setPWM(15,0,SERVOMAX);
delay(500);

in the loop part of the program with no need for the for loops.
In my project it made it nice to do it this way I found in the case where it is moving to a point and then you can interrupt the motion and tell it a new position to start moving to, whereas with the for loops the for loop runs to completion and then you could give it a new position to move to.

So anyway my question is whether this is a bad idea for some reason unknown to me I don't want to tell people something that might burn out the motor or the board or anything. I also don't know if this only applies to code using the 16 channel 12C chip or in general as I've only tested using that board.

Also Adafruit rocks I got all my stuff in 2 days awesome!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Concerning the 16 Channel 12C and servo controlling example code

Post by adafruit_support_mike »

It's okay to tell a servo to go to a given position without using a loop.

Usually a loop will also contain a delay() statement that moves the servo from one position to another more slowly, or keeps two servos in specific positions relative to each other.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”