#define MAX_SSD_CNT 3
#define MAX_DATA_PINS 8
#define PIN_BASE 8
#define OFF 1
#define ONE 0
/*
Font macro creations for Common Cathode (CC) display
Pin No : 0 1 2 3 4 5 6 7
Segment : E D C DP G F A B
ZERO : 1 1 1 0 0 1 1 1 -> 0xE7
ONE : 0 0 1 0 0 0 0 1 -> 0x21
Find the other definitions below
*/
#define ZERO 0xE7
#define ONE 0x21
#define TWO 0xCB
#define THREE 0x6B
#define FOUR 0x2D
#define FIVE 0x6E
#define SIX 0xEE
#define SEVEN 0x23
#define EIGHT 0xEF
#define NINE 0x6F
#define DOT 0x10
#define BLANK 0x00
/* Need to fill all others */
#define M_ONE 0x9D
#define MINUS 0xFD
#include <Arduino.h>
void init_ssd(void);
void display(unsigned char data[]);
void init_ssd(void) {
int pin;
for (pin = 0; pin < MAX_DATA_PINS; pin++)
pinMode(pin, OUTPUT);
/*
Initializing control lines
Pin No : 8 9 10
Display : D1 D2 D3
*/
for (pin = PIN_BASE; pin < (PIN_BASE + MAX_SSD_CNT); pin++)
pinMode(pin, OUTPUT);
}
/* Better if implemented in timer handler */
void display(unsigned char data[]) {
unsigned char digit;
int pin;
for (digit = 0; digit < MAX_SSD_CNT; digit++) {
/* Make sure all the display is OFF to start with */
for (pin = 0; pin < MAX_SSD_CNT; pin++)
digitalWrite(PIN_BASE + pin, OFF);
/* Put the data on the pins */
for (pin = 0; pin < MAX_DATA_PINS; pin++)
digitalWrite(pin, !!((data[digit] << pin) & 0x80));
// 0x6B - 01101011
// (01101011 << 0) & 10000000) -> 00000000 -> !!00000000 -> 0
// (11010110 << 1) & 10000000) -> 10000000 -> !!10000000 -> 1
// (10101100 << 2) & 10000000) -> 10000000 -> !!10000000 -> 1
// (01011000 << 3) & 10000000) -> 00000000 -> !!10000000 -> 0
// (10110000 << 4) & 10000000) -> 10000000 -> !!10000000 -> 1
// (01100000 << 5) & 00000000) -> 00000000 -> !!10000000 -> 0
// (11000000 << 6) & 10000000) -> 10000000 -> !!10000000 -> 1
// (10000000 << 7) & 10000000) -> 00000000 -> !!10000000 -> 1
/* Enable a specific display */
/*
Pin No: 8 9 10
0 1 1
1 0 1
1 1 0
*/
for (pin = 0; pin < MAX_SSD_CNT; pin++)
digitalWrite(PIN_BASE + pin, !(pin == digit));
// pin == digit
// First iteration
// 0 == 0 -> TRUE -> 1 -> !1 -> 0
// 1 == 0 -> FLASE-> 0 -> !0 -> 1
// 2 == 0 -> FLASE-> 0 -> !0 -> 1
// Second iteration
// 0 == 1 -> FALSE-> 0 -> !0 -> 1
// 1 == 1 -> TRUE -> 1 -> !1 -> 0
// 2 == 1 -> FLASE-> 0 -> !0 -> 1
// Third iteration
// 0 == 2 -> FALSE-> 0 -> !0 -> 1
// 1 == 2 -> FLASE-> 0 -> !0 -> 1
// 2 == 2 -> TRUE -> 1 -> !1 -> 0
}
}
const unsigned char digits[] = {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE};
static unsigned char ssd[MAX_SSD_CNT];
void setup() {
init_ssd();
}
void loop() {
static int count;
static int wait = 0;
for (int j = 0; j < 3; j++) {
ssd[j] = digits[(count)%10];
}
display(ssd);
if (!wait--) {
wait = 5000;
count++;
}
}