Contoh program rotary encoder
I've tested this library with one rotary encoder and a MCP23017, but the code is structured in a way that adding more encoders is just adding an entry in an array.
#CONTOH PROGRAM ROTARY ENCODER SOFTWARE#
At the cost of 2 more pins on the microcontroller, we can create another software bit-banged I2C bus, each of which adds again a maximum of 64 rotary encoders.Īssuming D2 to D13 and A0 to A5 are free, on these 18 pins we can have 9 I2C buses with a total of 72 MCP23017 devices hosting a grand total of 576 rotary encoders. Thus, with one I2C bus, which uses 2 pins, we can have a maximum of 8xMCP23017 and 64 rotary encoders (assuming no interrupts are used, which would need 1 pin for any number of rotary encoders). This means we can have 2^3 = 8 such device on the same I2C bus (i.e., connected to the same SDA and SCL lines). However the MCP23017 also has three address pins with which its I2C address can be selected. Since one MCP23017 has 16 ports, we can connect up to 8 rotary encoders to one such device. It has an example for the polling method and the interrupt method.įor 1 encoder, one can write down schematic like: (interrupt based) The library is a simple header file which defines a RotaryEncOverMCP C++ object, with which a rotary encoder connected to an MCP23017 device can be easily described and managed. The Rotary library also handles debouncing by using a state-machine based approach for decoding. The written library uses a modified Adafruit MCP23017 library and the Rotary library.
Tests were made using an MCP23017 and a KY-040. A PCF8574 would have also worked just fine, since it has the same capabilites. I've chosen a MCP23017 here because it is interrupt-capable, has 16-bit and I had it lying around. Using an ATTiny85 per encoder and possibly joining them via an I2C bus is also possible, however more expensive and more work.
This means that there can be multiple (up to 127) devices on the I2C bus, and each I2C device can then e.g. Using a port expander over I2C has the advantage being a bus that only uses 2 pins. ValRotary value is the value of the number of steps that have been running. Contoh penggunaan rotary encoder oleh StufiMedia Tinggalkan komentar. KRN100 Firmware Contoh Program Komunikasi PC Contoh Program HMI.