Please note that I am a novice and do not have a whole lot of experience with arduino.
So I am trying to set the position of multiple servo motors to their designated positions. In order to make it more efficient, I am using a for loop and an array of positions. I am testing this concept with two servos before I test it with more. For some reason, none of the servos will go to their correct orientations. It was just working not too long ago. Here is the code:
#include <Servo.h>
Servo servos[2];
int positions[]={90,90};
void setup() {
for (int i; i<2; i++){
servos[i].attach(i+11);
}
for (int i; i<2; i++){
servos[i].write(positions[i]);
}
}
void loop() {
}
It's hard to tell what's connected to what.
Better to draw out a circuit - clearly separating power sources etc...
REMEMBER you cannot supply the servo +V from the Arduino!
It looks like your power supply goes straight into the Arduino - then out to the breadboard.
The servos require more than the board can supply, an dit will becoem 'dirty' as the servos operate - hence must be isolated from the logic on the cpu board.
Depending on the type of servos, and type of power supplies that you have available.
The simple calculations above make it easy.
Big servos most probably use more power (Volts x Amps)
Big power supplies get more expensive - hence the suggestion of clusters or groups that can be powered independently.
The first part of a for loop is the initialization section. This statement says "Starting with i equal to whatever value is present in the memory address referenced by i, while i is less than 2, do something, and then increment i.
Surely, THAT is not what you intended. If it was, you should be pursuing other interests. A career as a programmer is not in your future.
When the compiler reports problems, where in the list do you start fixing things? I get better results when I start at the top. I fix one issue, and try again.
I look at code the same way. I see something obviously stupid, and I don't even read what the poster thinks the problem is.