/* * This example demonstrates the use of RGBEncoder to control a stepper motor. */ // Include library #include "RGBEncoder.h" int i = 0; // Create object of RGBEncoder RGBEncoder knob; // Handler. Called when the encoder is turned left void stepLeft() { Serial.println(knob.getEncoderValue()); } // Handler. Called when the encoder is turned right void stepRight() { Serial.println(knob.getEncoderValue()); } void setup() { Serial.begin(9600); knob.begin(); // initialisation //knob.setStep(1); knob.setRange(-100, 100); // Register on-step handlers knob.onStepLeft(stepLeft); knob.onStepRight(stepRight); } void loop() { knob.update(); // upkeep to trigger the handler when necessary }