A rotary encoder, although looking similar to a potentiometer, is actually a pair of mechanical connections that are closed and then opened in a particular order and timing depending on the direction and speed that the connecting shaft is rotated.
Furthermore, an encoder (unlike a potentiometer) does not have a maximum and minimum excursion, making it ideal for contextual values, delta data points, and parameters that need accurate adjustment beyond a finite number of turns.
As a result, the output of an encoder can be read and interpreted to give direction (left or right) as well as some sense of speed of turning, in combination with limitless rotations.
The Teensy has a great library for using the encoder, which is part of the Teensyduino installation. More information about the library and its use can be found here: https://www.pjrc.com/teensy/td_libs_Encoder.html.
An encoder can make for a useful MIDI control.
Hardware Setup
To begin with a single encoder is connected to digital pins 25 and 26. The middle leg of the encoder is connected to ground.
Example 1 - Reading the Value of One Encoder
In this example, an encoder object is created, using digital pins 25 and 26. The value of the encoder is read and compared to the previous reading. If the value of the reading has changed compared to the previous reading, then the value is sent to the Serial Monitor.
No constraints are set on reading the value of the encoder, and so there is no limit on the reading when turning the encoder left or right.
Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Using_Encoders_Example_1/
Example 2 - Reading the Value of One Encoder, and Send as MIDI Continuous Control Message
In this example, an encoder object is created, using digital pins 25 and 26. The value of the encoder is read and compared to the previous reading. If the value of the reading has changed compared to the previous reading, then the value is sent as a MIDI continuous control message
The value is constrained to the range 0 - 127, so turning the encoder beyond 127 or below 0 will have no effect.
Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Using_Encoders_Example_2/
Example 3 - Reading the Value of Two Encoders, and Send as MIDI Continuous Control Messages
In this example, two encoder object are created, using digital pins 25 - 28. The value of the encoders are read and compared to previous readings. If the value of a reading has changed compared to the previous reading, then the value is sent as a MIDI continuous control message. Each encoder has a separate controller number.
The values are constrained to the range 0 - 127, so turning the encoders beyond 127 or below 0 will have no effect.
Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Using_Encoders_Example_3/
Example 4 - Four Encoders Plus One Button as Bank of Switchable MIDI Controllers
In this example, four encoders are used alongside a button. The button switches between four different banks. Each bank is represented by the four physical encoders. Each bank has unique, four MIDI controller numbers, thereby having a total of sixteen MIDI controllers.
All values are stored as the banks are switched.
Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Using_Encoders_Example_4/
Summary
Encoders can be used in addition to buttons and switches for controlling parameters. The limitless rotation can be used in different contexts than a standard potentiometer.
0 comments:
Post a Comment