     limitSwitchCloseActive = (digitalRead(PIN_LIMITSWITCH_CLOSE) == LOW);
 }
 
+void updateEncoder(int previous, int current) {
+    static int grayToBinary[4] = { 0, 1, 3, 2 };
+    previous = grayToBinary[previous & 0x3];
+    current = grayToBinary[current & 0x3];
+
+    if (current == ((previous+1) & 0x3))
+        encoderPosition++;
+    if (current == ((previous-1) & 0x3))
+        encoderPosition--;
+}
+
 void encoderGate1ISR() {
     int previousEncoderState = encoderState;
     encoderState = (encoderState & 0x1) | (digitalRead(PIN_ENCODER_GATE_1) == LOW ? 0x2 : 0);

static volatile int encoderState = 0;
static volatile int encoderPosition = 0;

void setup() {

    pinMode(PIN_BUTTON_CLOSE, INPUT);
    pinMode(PIN_BUTTON_OPEN, INPUT);
    pinMode(PIN_BUTTON_EMERGENCYSTOP, INPUT);

#include "Version.h"

#define BOARD_NAME "KOMAROOF"
#define PIN_UNUSED 46
#define PIN_ONE_WIRE_BUS 44
#define PIN_BUTTON_CLOSE 42
#define PIN_BUTTON_OPEN 40
