| Index

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

Name |  | ### attach()
Examples |  |
    #include <Encoder.h>

    Encoder myEncoder;

    void setup() {
      myEncoder.attach(2, 8)  // attaches a encoder with phaseA connected to pin 2 and phaseB connected to pin 8
    }

    void loop() {
      myEncoder.write(0);  // position the encoder angle at 0
    }
    #include <Encoder.h>

    Encoder myEncoder;
    Encoder mySecondEncoder;

    void setup() {
      myEncoder.attach(2, 8)        // attaches an encoder with phaseA connected to pin 2 and phaseB connected to pin 8
      mySecondEncoder.attach(3, 15) // attaches an encoder with phaseA connected to pin 3 and phaseB connected to pin 15
    }

    void loop() {
      myEncoder.write(myencoder, 0); // position the encoder angle at 0
      mySecondEncoder.write(100);    // position the encoder angle at 100
    }
Description |  | The Wiring encoder library provides for 4 encoder channels, so it can drive up to 4 encoders at a time. The encoder's phaseA cable can be connected to digital I/O pins 2, 3, 38 or 39 exclusively, on the Wiring I/O board. This is because the 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 |  |
pinA |  | Encoder phase A pin, it can be 2, 3, 38 or 39
pinB |  | Encoder phase B pin, it can be any Wiring pin
encoder |  | The Encoder variable.
Returns |  | None
Usage |  | Application