|
|
@ -28,7 +28,7 @@ bool Rotary::begin(uint8_t pinA, uint8_t pinB, uint8_t pinButton) { |
|
|
|
"encoderTask", /* String with name of task. */ |
|
|
|
2048, /* Stack size in words. */ |
|
|
|
this, /* Parameter passed as input of the task */ |
|
|
|
tskIDLE_PRIORITY+2, /* Priority of the task. */ |
|
|
|
tskIDLE_PRIORITY+1, /* Priority of the task. */ |
|
|
|
&taskHandle); /* Task handle. */ |
|
|
|
|
|
|
|
attachInterrupt(digitalPinToInterrupt(pinA), doEncoder, CHANGE); |
|
|
@ -47,7 +47,8 @@ void Rotary::task(void *pvParameters) { |
|
|
|
uint32_t ulNotificationValue; |
|
|
|
while(true) { |
|
|
|
ulNotificationValue = ulTaskNotifyTake( pdTRUE, portMAX_DELAY ); |
|
|
|
delay(2); // wait until bounce settled
|
|
|
|
Serial.println("rotation task"); |
|
|
|
delay(1); // wait until bounce settled (1 or 2 is fine)
|
|
|
|
|
|
|
|
if (digitalRead(pinButton) == HIGH) { |
|
|
|
buttonPressed = true; |
|
|
@ -75,8 +76,9 @@ void Rotary::task(void *pvParameters) { |
|
|
|
|
|
|
|
ulNotificationValue = ulTaskNotifyTake( pdTRUE, 0 ); // clear pending notifications
|
|
|
|
|
|
|
|
debouncePulses++; |
|
|
|
if (debouncePulses > 3) { // update every 4 pulses
|
|
|
|
// debouncePulses++;
|
|
|
|
// if (debouncePulses > 3) { // update every 4 pulses
|
|
|
|
if (digitalRead(pinB) == HIGH && digitalRead(pinA) == HIGH) { // update everytime inbetween positions
|
|
|
|
debouncePulses = 0; |
|
|
|
if (encoderPos > encoderPosOld+1) { |
|
|
|
value++; // if the value has at least changed for 2
|
|
|
|