Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a ready to compile example-code? #6

Open
StefanL38 opened this issue Nov 28, 2021 · 1 comment
Open

Adding a ready to compile example-code? #6

StefanL38 opened this issue Nov 28, 2021 · 1 comment

Comments

@StefanL38
Copy link

Hi John,

I was looking at the example-code in the comment-section of the encoder.h

/* USAGE FOR ONE ENCODER:
// define the input pins
#define pinA 19
#define pinB 20
#define pinP 21
// create an encoder object initialized with their pins
Encoder encoder( pinA, pinB, pinP );
// setup code
void setup() 
{
  // start the encoder time interrupts
  EncoderInterrupt.begin( &encoder );
}
// loop code
void loop()
{
  // read the debounced value of the encoder button
  bool pb = encoder.button();
  // get the encoder variation since our last check, it can be positive or negative, or zero if the encoder didn't move
  // only call this once per loop cicle, or at any time you want to know any incremental change
  int delta = encoder.delta();
  // add the delta value to the variable we are controlling
  myEncoderControlledVariable += delta;
  // do stuff with the updated value
  // that's it
}
*/  
´´´
it is missing the include-compiler-directive
Would you mind adding this to make the code ready to compile?

best regards Stefan 
@alto777
Copy link

alto777 commented Mar 18, 2022

If you do, maybe add a global:

unsigned long myEncoderControlledVariable;

so it compiles.

You could put something like the below in the loop where you tell us to do stuff:

  static long printed;
  if (myEncoderControlledVariable != printed) {
  	Serial.println(myEncoderControlledVariable);
  	printed = myEncoderControlledVariable;
  }

But yeah, at least the include thing.

alto777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants