Libraries \ Encoder

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

Encoder

Name

write()

Examples
#include <Encoder.h> 
 
int val; 
Encoder myEncoder; 
 
void setup() { 
  // ataches the encoder to pins EI2 and pin 8
  // EI2 is pin 18 on Wiring S
  // EI2 is pin 2 on Wiring v1
  myEncoder.attach(EI2, 8); 
  myEncoder.write(0); // set the encoder position to 0
  Serial.begin(9600);
} 
 
void loop() { 
  // Reads the position or angle of the encoder variable 
  val = myEncoder.read();          // read position
  Serial.print("Encoder is at: "); // print the position
  Serial.println(val);
  delay(100); // wait 100ms for next reading
}
Description The write() method sets the the encoder position, it can be used to initialize it, or reset it.
Syntax
encoder.write(value)
Parameters
value int
encoder The Encoder variable
Returns None
Usage Application
Updated on July 07, 2011 11:09:56pm PDT

Creative Commons License