Search wiring.org.co:

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.

Name |

### Encoder

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 | Encoders are sensors used to track absolute or relative position. The Wiring Encoder library allows for easily manipulating shaft encoders. Encoders generate pulses when moved, on each pulse triggering an event on the Wiring I/O board, for this reason the phaseA pin of an encoder can only be connected to a Wiring pin capable of generating external interrupts. On Wiring v1 boards the external interrupts capable pins are: 0, 1, 2, 3, 36, 37, 38 and 39 named EI0, EI1, .. EI7 respectively. On Wiring S board the external interrupts capable pins are: 2, 3 and 18 named EI0, EI1 and EI2 respectively.
Syntax |
    Encoder
Methods |

attach() |
detach() |
write() |
read() |
attached() |

Returns | None
Usage | Application

Updated on July 07, 2011 11:09:54pm PDT