All Projects → Billwilliams1952 → KY-040-Encoder-Library---Arduino

Billwilliams1952 / KY-040-Encoder-Library---Arduino

Licence: other
Arduino library for the KY-040 Encoder

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to KY-040-Encoder-Library---Arduino

RotaryEncoder
This is small and fast Arduino library for Rotary Encoder with interrupts.
Stars: ✭ 60 (+62.16%)
Mutual labels:  encoder, arduino-library, ky-040
Arduino
🚀 Proyectos de todo tipo para arduino utilizando sus sensores y actuadores. 🤖
Stars: ✭ 27 (-27.03%)
Mutual labels:  arduino-library, arduino-boards, arduino-platform
duino-coin
ᕲ Duino-Coin is a coin that can be mined with almost everything, including Arduino boards.
Stars: ✭ 626 (+1591.89%)
Mutual labels:  arduino-boards, arduino-platform
arduino-primo-tutorials
Here some tutorials to explain and show how to make use of the new features of the Arduino Primo and Arduino Primo Core, such as Wifi, BLE, NFC, InfraRed and various sensors. Hope you can find this helpful to create amazing stuff, save the planet or make a cool project to look smart at the dinning table with your uncles.
Stars: ✭ 12 (-67.57%)
Mutual labels:  arduino-library, arduino-boards
ArduRTOS
Real Time Operating System Lessons using Arduino and The FreeRTOS Kernel
Stars: ✭ 46 (+24.32%)
Mutual labels:  arduino-boards, arduino-platform
Arduino Foc
Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
Stars: ✭ 387 (+945.95%)
Mutual labels:  encoder, arduino-library
Arduino Boards Index
Electronic Cats Package Lists for the Arduino Board Manager
Stars: ✭ 14 (-62.16%)
Mutual labels:  arduino-boards, arduino-platform
Simulink-Arduino-Serial
How to connect Arduino and Simulink
Stars: ✭ 54 (+45.95%)
Mutual labels:  arduino-boards, arduino-platform
Loom
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Stars: ✭ 24 (-35.14%)
Mutual labels:  arduino-library
DirectIO
Fast, simple I/O library for Arduino
Stars: ✭ 109 (+194.59%)
Mutual labels:  arduino-library
AutomationShield
Arduino library and MATLAB/Simulink API for the AutomationShield Arduino expansion boards for control engineering education.
Stars: ✭ 22 (-40.54%)
Mutual labels:  arduino-library
Pixie Chroma
Arduino library and documentation for Pixie Chroma displays!
Stars: ✭ 33 (-10.81%)
Mutual labels:  arduino-library
OttoDIYLib
Latest and official Libraries for Arduino Otto DIY robots
Stars: ✭ 56 (+51.35%)
Mutual labels:  arduino-library
PCF8575 library
Library to use i2c digital expander with arduino, esp8266 and esp32. Can read write digital value with only 2 wire (perfect for ESP-01).
Stars: ✭ 28 (-24.32%)
Mutual labels:  arduino-library
Arduino-FrequencyDetector
Fast audio frequency detector without fft for plain Arduino and Attiny85. Whistle switch example included.
Stars: ✭ 22 (-40.54%)
Mutual labels:  arduino-library
SparkFun ADXL345 Arduino Library
Arduino Library for the ADXL345
Stars: ✭ 34 (-8.11%)
Mutual labels:  arduino-library
TelnetStream
Arduino Stream implementation over Telnet for OTA logging and debugging
Stars: ✭ 101 (+172.97%)
Mutual labels:  arduino-library
cryptosuite2
Cryptographic suite for Arduino (SHA, HMAC-SHA)
Stars: ✭ 23 (-37.84%)
Mutual labels:  arduino-library
RingBuffer
A RingBuffer library for Arduino
Stars: ✭ 34 (-8.11%)
Mutual labels:  arduino-library
Arduino RT-Thread
RT-Thread library optimized for Arduino.
Stars: ✭ 38 (+2.7%)
Mutual labels:  arduino-library

KY-040-Encoder-Library---Arduino

Synopsis

Arduino library for the KY-040 Encoder.

This library allows the user to connect one or more encoders to any of the interrupt pins supported by your board. The user may then add rotaries that will each keep track of the encoder movement while active. Each rotary is initialized with the rotary ID (a byte value between 0 - 254), an initial integer value, and integer values for minimum, maximum, and increment. Also a boolean rollover flag controls whether the current rotary value wraps from min to max or max to min.

Note, memory for the total number of rotaries for an encoder is allocated during object creation. If you attempt to add a rotary using AddRotaryCounter that exceeds the limit set during object creation, the function will return false.

The KY-040 encoder library uses interrupts on the clock line. Because of switch bounces, a 470 nF (0.47 uF) capacitor is required on each encoder clock (CLK) pin to ground.

Recent bug fixes and modifications:

Date Changes
10/11/2017 Example program now supports up to four encoders. Tested on an Arduino Micro. Updates to ky040.cpp and ky040.h to support SMALLEST_CODESIZE, which, if defined, removes all runtime sanity checks. This option is for those who may be running low on program memory.
1/20/2017 Finalized support for multiple Arduino board types
Same Bug fixed - when clkPin not correct, all functions should gracefully fail.

Some information on the encoder may be found at http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/keyes-ky-040-arduino-rotary-encoder-user-manual/

Switch Bounce on Clock (interrupt) line (top trace)

alt tag

0.47 uF capacitor connected between CLK line and ground

alt tag

Installation

Download the ZIP file and extract into your sketchbook/libraries directory. Exit the Arduino program (if open) and restart it to see the KY-040 library with its sketch examples.

API Reference

ky040 ( uint8_t interruptClkPin, uint8_t dtPin, uint8_t switchPin, uint8_t maxRotarys = 1 );
	
// Create a rotary counter specifying all parameters.
bool AddRotaryCounter ( uint8_t id, int16_t currentVal, int16_t minVal,
			int16_t maxVal, int16_t inc = 1, bool rollOver = true );
			
// Support simple rotary counters from 0 to maxVal.
bool AddRotaryCounter ( uint8_t id, int16_t maxVal, bool rollOver = false );
	
// Make rotary number 'id' the active one - responding to user inputs.
bool SetRotary ( uint8_t id );

// True if rotary number 'id' value has changed.
bool HasRotaryValueChanged ( uint8_t id = CURRENT_ID );

// Force a changed status for rotary number 'id'.
void SetChanged ( uint8_t id = CURRENT_ID );
	
// Get the current rotary value for roatary number 'id'. After this call, HasRotaryValueChanged returns false.
int16_t GetRotaryValue ( uint8_t id = CURRENT_ID );

// Change the maximum allowed value on rotary number 'id'.
void SetMaxValueOnRotary ( int16_t maxVal, uint8_t id = CURRENT_ID );

// True if rotary number 'id' is the active one.
bool IsActive ( uint8_t id );

// True if the switch associated with the encoder is pressed.
bool SwitchPressed ( void );

This program uses the Arduino API (Arduino.h) and stdlib.h; no other special libraries are required. It has been tested on the Arduino Micro.

Tests

Use the EncoderTest example program to verify correct operation. Be sure to connect a 0.47 uF capacitor from the encoder CLK pin to ground. Also, a sketch using multiple rotaries for one encoder may be found under https://github.com/Billwilliams1952/Arduino-Controlled-Fan-Tester.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].