Code Monkey home page Code Monkey logo

basicencoder's People

Contributors

micromouseonline avatar

Watchers

 avatar  avatar

basicencoder's Issues

Faulty example code in README.md

This repository's README contains the following code snippet:

void loop() {
  int encoder_change = encoder.get_change();
  if (encoder_change) {
    Serial.println(encoder.get_change());
  }      
}

As pointed out within the same readme, the Serial.println() command will always print a 0 here, because the first call to encoder.get_change() has reset the input counter.

The correct call would be "Serial.println(encoder_change);". Could you please correct this?

Call to noInterrupts()

Hello,

first of all thank you for the library.

I just saw the code, and there are some calls to noInterrupts().
According to the docs, after a call to noInterrupts(), interrupts() must be called for interrupts to be enabled again.
Is it intentional that you leave out the calls to interrupts() or is it an error?

Two Rotary-Encoders

I want to have two encoders in one script. I assumed it would work like this:

#include <Arduino.h>
#include <BasicEncoder.h>
#include <TimerOne.h>

BasicEncoder encoder(8, 9);
BasicEncoder encoder2(10, 11);

void timer_service() {
  encoder.service();
  encoder2.service();
}

void setup() {
  Serial.begin(230400);
  Serial.println("Starting..");
  Timer1.initialize(1000);
  Timer1.attachInterrupt(timer_service);
}

void loop() {
  int encoder_change = encoder.get_change();
  if (encoder_change) {
    Serial.print("Encoder 1: "); Serial.println(encoder.get_count());
  }      
  int encoder2_change = encoder2.get_change();
  if (encoder2_change) {
    Serial.print("Encoder 2: "); Serial.println(encoder2.get_count());
  }      
}

However, when I use this code, both values will change when I turn any of the rotary-encoders, and sometimes they enter a feedback-loop where both of the values will change (equally) endlessly.
I am really bad at Arduino/C, so am I doing something obvious wrong, or is the error somewhere else than on my side here?

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.