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 | attach() |
||||||
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 Wiring encoder library is based on external interruptions which can only happen on these specific pins. The phaseB cable can be connected to any other digital I/O pin of the Wiring I/O board. The attach(phaseAPin, phaseBPin) method attaches an Encoder variable to the pins where the encoder is connected. | ||||||
Syntax | encoder.attach(pinA, pinB) |
||||||
Parameters |
|
||||||
Returns | None | ||||||
Usage | Application |