Giter Site home page Giter Site logo

arduino-encoder-counter's Introduction

Example: Arduino Encoder Counter

Example code that demonstrates how to decode a Quadrature Rotary Encoder using Arduino interrupts.

Includes several unique features:

Using ATmega Pin-Change interrupt instead of the external interrupt

Using the Pin Change Interrupt allows connecting encoders and buttons to any of the Arduino pins, not just the two External Interrupt enabled pins. While maintaining the ability of immediate reaction to any encoder rotation changes.

In the example code the Pin Change Interrupt used catches any changes on the ATmega PORTD pins. Should you need to use different pins, the PCINT*_vect and the interrupt setup need to be changed with the appropriate port settings.

8-bit state machine for discrete increment/decrement of an integer number

The four states of the Quadarture Rotary Encoder are stored in a LIFO queue that acts as the history of a state machine. The queue itself is an 8-bit integer that can be compared with the CW or the CWW sequence of events to match a clocked change by the encoder.

Two-State push button with variable

It is common for rotaty encoders to also incorporate a push-button; The code includes an example of how this button can be used to switch states using an 2-bit function selector.

Bit plot of the PORTD pins

The code includes an example on how the 8-bits can be printed in binary notation with left zero padding. This can be used during debug to show the state of the pins to the serial console or any connected display device.

Serial output of the inc/dec number and function selector state

Example of how the loop() function of the Arduino can be used to wait for changes and be "normally sleeping" until something is changed with the encoder number and/or state selected by the push button.

In situations where the Arduino loop() is being used to change state of external components such as LEDs and/or OLED displays, having to only send changes when these have happened reduces wire noise and power usage.

Authors

License

  • This project is licensed under the BSD License - see the LICENSE file for details.

arduino-encoder-counter's People

Contributors

kesor avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.