Skip to content

SetEncoderValue()

Arnd edited this page Dec 13, 2016 · 1 revision

SetEncoderValue(NewValue);

This function will set the current value of the encoder as signed 16 bit integer ranging from -32,768 to 32,767. Any rotations of the encoder after this call will increment or decrement from the new value. Note that each detent ("click") of the encoder will add (when turning clockwise) or subtract (when going counter-clockwise) 4 from the counter, so to make things simpler the new value should be divisible by 4.


Example:

// Instantiate the class using all of the pins defined in constants     //
EncoderClass Encoder(ROTARY_PIN_1, ROTARY_PIN_2, PUSHBUTTON_PIN, RED_PIN, 
                     GREEN_PIN, BLUE_PIN);

void setup() {
  Serial.begin(115200);
  delay(1000);
  Encoder.SetEncoderValue(16); // set a new value
  Serial.print("New encoder value is ");
  Serial.println(Encoder.GetEncoderValue());
} // of method setup()
void loop(){
  // code goes here //
} // of method loop()