Code Example

// Code by Brian Patton
// 2/25/2016
// feel free to do whatever you wish with it

const int Servo0 = 0; //Pin Servo is connected to
int i;  //Servo Position tracker

void setup() {
  pinMode(Servo0, OUTPUT);  // Set Servo pin to Output
  Serial.begin(9600);       // Create a Serial Port
  while (!Serial);          // Wait for Serial Window to open
}
//**************************************************
// Funtion to graph position
void PrintPosition() {
  //Have to move graph 1000 spaces left to start at begining of page
  // Divide by 10 to scale it to a single page
  for (int z = 0; z <= (i - 1000) / 10; z++) { //move curser to position
    Serial.print(" ");
  }
  Serial.println("*");
// Create axis..not perfect since characters and spaces are not the same size
  Serial.print("1000uS");
  for (int z = 0; z <= (1494 - 1000) / 10; z++) {
    Serial.print(" ");
  }
  Serial.print("|");
  for (int z = 0; z <= (1450 - 1000) / 10; z++) {
    Serial.print(" ");
  }
  Serial.println("2000uS");
}
//**************************************************
// Main Loop
void loop() {
  // Creat loop to change pulses from 1000 to 2000uS
  for (i = 1000; i <= 2000; i = i + 2) {
    digitalWrite(Servo0, HIGH); //Set pin High
    delayMicroseconds(i);       // wait i microseconds
    digitalWrite(Servo0, LOW);  //Set pin Low
    delay(20);                  // 20 millisecond delay
    PrintPosition();            // Call to Graph
  }
  // Creat loop to change pulses from 2000 to 1000uS
  for (i = 2000; i >= 1000; i = i - 2) {
    digitalWrite(Servo0, HIGH); //Set pin High
    delayMicroseconds(i);       // wait i microseconds
    digitalWrite(Servo0, LOW);  //Set pin Low
    delay(20);                  // 20 millisecond delay
    PrintPosition();            // Call to Graph
  }
}