MIDI Transport Controller

Testing the Arduino Jog Sketch - Version 2

Sketch Featuring Software Debounce

 
/* Test jog wheel
     with 10 millisecond debounce
*/

byte jog0 = 2;
byte jog1 = 4;
volatile int jog = 0;
int lastJog = -1;
unsigned long lastJogTime = millis();
    
void setup() {
    pinMode(jog0, INPUT);
    pinMode(jog1, INPUT);
    digitalWrite(jog0, HIGH);
    digitalWrite(jog1, HIGH);
    attachInterrupt(0, updateJog, FALLING);
    Serial.begin(9600);
}   

void loop() {
    if (jog != lastJog) {
        Serial.println(jog, DEC);
        lastJog = jog;
    }
    delay(250);
}

void updateJog() {
    unsigned long now = millis();
    if (now - lastJogTime > 10) {
        lastJogTime = now;
        if (digitalRead(jog1)) {
            jog++;
        } else {
            jog--;
        }
    }
}

Next step: Arduino sketch for the shuttle ring.


<<Previous Page | Index |