#include <SoftwareSerial.h>
// pin 6 is to receive from the controller and does not need to be connected
// pin 7 needs to be connect to the serial data input of the board
SoftwareSerial pololu(6, 7);
int pos = 0;
void setup() {
Serial.begin(9600);
pololu.begin(9600);
}
void loop() {
Serial.println(pos);
// set position for eight servos simultaneously
for(int i=0; i<8; i++) {
setPosition(i, pos);
}
pos++;
if(pos == 255) {
pos = 0;
}
delay(10);
}
void setPosition(int servo, int pos) {
servoControllerpololu.write(0xFF); // write synchronization flag
servoControllerpololu.write(servo); // write servo number
servoControllerpololu.write(pos); // write position
} |