Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagecpp
#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) {
  pololuservoController.write(0xFF); // write synchronisation pololuflag
  servoController.write((byte)servo); //  pololuwrite servo number
  servoController.write((byte)pos); // write position
}