Libraries \ Servo

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Class

Servo

Name

readMicroseconds()

Examples
#include "Servo.h"

int myled = 0;
Servo myservo;

void setup() {
  pinMode(myled, OUTPUT);
  // set off the LED
  digitalWrite(myled, LOW); 
  // attaches a servo connected to pin 2 
  myservo.attach(2);
}

void loop() {
  // sets the servo position at 90 degrees
  myservo.writeMicroseconds(1494);  

  // if servo position is greater than 90 degrees 
  if (myservo.readMicroseconds() >= 1494)   
  { 
    // turn on the LED 
    digitalWrite(myled, HIGH);
  }
}
Description The readMicroseconds() method returns the last written servo pulse width in microseconds.
Syntax
servo.readMicroseconds()
Parameters
servo Any variable of type Servo
Returns int
Usage Application
Updated on July 07, 2011 11:11:31pm PDT

Creative Commons License