/*
7 segment single digit demo
Cycles through the numerals 0 to 9, then
approximations of the letters a - z, a dash,
(minus sign), and a blank.
The lookup table is written for common cathode,
but the code below inverts the bits for use with
common anode displays.
*/
#include "segment_lookup.h"
const unsigned long ONE_SEC = 1000;
const int NUM_CHARS = 38;
// define segment pins (A to G, DP)
const int SEG_PINS[8] = {5, 4, 6, 9, 8, 10, 11, 7};
unsigned long prevTime = 0;
int count = 0;
void showDigit(int num) {
for (int i = 0; i < 8; i++) {
// ! inverts the segment bit look up value
digitalWrite(SEG_PINS[i], !SEGMENTS[num][i]);
}
}
void setup() {
Serial.begin(115200);
for (int i = 0; i < 8; i++) {
pinMode(SEG_PINS[i], OUTPUT);
}
}
void loop() {
// this block executes every ONE_SEC
if (millis() - prevTime >= ONE_SEC) {
prevTime = millis();
count++;
if (count >= NUM_CHARS) count = 0;
}
// this must be called frequently
showDigit(count);
}