/* interrupt routine for Rotary Encoders tested with Noble RE0124PVB 17.7FINB-24 http://www.nobleusa.com/pdf/xre.pdf - available at pollin.de and a few others, seems pretty universal The average rotary encoder has three pins, seen from front: A C B Clockwise rotation A(on)->B(on)->A(off)->B(off) CounterCW rotation B(on)->A(on)->B(off)->A(off) and may be a push switch with another two pins, pulled low at pin 8 in this case raf@synapps.de 20120107 */ #include "rotary.h" //using namespace std; Rotary::Rotary() {} bool Rotary::begin(uint8_t pinA, uint8_t pinB, uint8_t pinButton) { this->pinA = pinA; this->pinB = pinB; this->pinButton = pinButton; pinMode(pinA, INPUT_PULLUP); pinMode(pinB, INPUT_PULLUP); pinMode(pinButton, INPUT_PULLUP); encoder = new ClickEncoder(pinA, pinB, pinButton, 4); //encoder->setButtonOnPinZeroEnabled(true); xTaskCreate( &cTaskWrapper, /* Task function. */ "encoderTask", /* String with name of task. */ 1024, /* Stack size in words. */ this, /* Parameter passed as input of the task */ tskIDLE_PRIORITY+2, /* Priority of the task. */ &taskHandle); /* Task handle. */ return true; } void Rotary::cTaskWrapper(void* parameters) { static_cast(parameters)->task(NULL); } void Rotary::task(void *pvParameters) { while(true) { encoder->service(); value += encoder->getValue(); if (value != last) { last = value; if (callback) callback(value); } vTaskDelay(1 / portTICK_PERIOD_MS); } vTaskDelete(NULL); } bool Rotary::registerCallback(std::function callback) { this->callback = callback; return true; }