Dual Channel MIDI Foot Switch

Software

Testing the display circuit

The following test sketch exercises the pair of 74HC595 shift registers connected to the 2 7-segment LED displays. The sketch allows me to see if I have all of the pins connected correctly and if my character maps are correct by cycling through all of the possible digits.

Test Code

// 7-Segment Test sketch
// Counts from 0 to 99 on 2-digit 7-segment displays
// (C) 2011, bechter.com - All Rights Reserved

int latchPin = 4;  // 74HC595 ST_CP
int clockPin = 3;  // 74HC595 SH_CP
int dataPin = 2;   // 74HC595 DS

// 7-Segment character map
unsigned int digits[10] = { 0x81, 0xf3, 0x49, 0x61, 0x33,
                            0x25, 0x05, 0xf1, 0x01, 0x21 };

void setup() {
    // set pins 2, 3 and 4 to output to talk to the 74HC595
    pinMode(latchPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
}


void loop() {
    // count from 0 to 99 and repeat
    for (int j = 0; j < 100; j++) {
        // split number into tens and ones, substitute a blank (0xff)
        // for a zero in the tens digit because it looks classier.
        updateDisplay((j / 10 == 0) ? 0xff : digits[j / 10], digits[j % 10]);
        // sleep for a second between updates
        delay(1000);
    }
}


void updateDisplay(unsigned int digit0, unsigned int digit1) {
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, MSBFIRST, digit0);
    shiftOut(dataPin, clockPin, MSBFIRST, digit1);
    digitalWrite(latchPin, 1);
}


<<Previous Page | Index |