MIDI Transport Controller

Testing the Arduino Jog Sketch

Code Strategy


Jog wheel connections to Arduino

My first test sketch is very simple. The Arduino is on the breadboard (see schematic) with the three pins from the jog wheel connected to pins 2, 4 and GND. Pin 2 is configured as an interrupt and pins 2 and 4 are configured as inputs with internal pull-up resistors.

The idea behind the test is to have the rotating jog wheel send clock pulses triggering an interrupt. The second pin will send pulses to a digital input. With each interrup cycle, testing the input line will determine whether to increment or decrement the running total. The main loop of the sketch will print the value of the running total to the serial monitor, sleep briefly and repeat.

Test Code

/* Test jog wheel
*/


byte jog0 = 2;
byte jog1 = 4;
volatile int jog = 0;
int lastJog = -1;

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() {
    if (digitalRead(jog1)) {
        jog++;
    } else {
        jog--;
    }
}

<<Previous Page | Index | Next Page>>