Overview
An encoder is a digital input device that looks similar to a pot but can be rotated indefinitely and delta rotation in steps is measured by making or breaking contact between two pins and ground. The Teensy has an excellent and easy to use library for encoders. More than one encoder can be easily used.
Hardware
The encoder portion of an encoder usually has three pins, these may be labelled A, B and C. B is a common ground and should be connected to ground. A and C should each be connected to an individual digital pin on the Teensy. As the encoder is turned, the connection between A and B, and A and C is made and broken. This is, in turn, read as a series of high and low signals by the digital input pins.
This particular encoder also has a push switch. When pressed down, the encoder will make the connection between sw1 and sw2. sw1 can be connected to a third digital input pin on the Teensy and sw2 can be connected to ground.
Software
The code uses the encoder library to create an encoder object on pins 0 and 1 as well as a button on pin 2. There is a boundary of 0 and 1023 for the encoder. Values of the button and encoder are printed to the serial monitor.
0 comments:
Post a Comment