Encoder icon indicating copy to clipboard operation
Encoder copied to clipboard

Adding a ready to compile example-code?

Open StefanL38 opened this issue 4 years ago • 1 comments

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 

StefanL38 avatar Nov 28 '21 11:11 StefanL38

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

alto777 avatar Mar 18 '22 03:03 alto777