--- /dev/null
+#define A_PIN 8
+#define B_PIN 9
+#define C_PIN 3
+#define D_PIN 4
+#define E_PIN 5
+#define F_PIN 7
+#define G_PIN 6
+#define DP_PIN 2
+
+int print_digit(uint8_t digit);
+
+const uint8_t pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
+
+const uint8_t segment_map[16] =
+{
+ // A B C D E F G DP
+ 0b00000011, // 0
+ 0b10011111, // 1
+ 0b00100101, // 2
+ 0b00001101, // 3
+ 0b10011001, // 4
+ 0b01001001, // 5
+ 0b01000001, // 6
+ 0b00011111, // 7
+ 0b00000001, // 8
+ 0b00001001, // 9
+ 0b00010001, // A
+ 0b11000001, // b
+ 0b01100011, // C
+ 0b10000101, // d
+ 0b01100001, // E
+ 0b01110001 // F
+};
+
+void setup()
+{
+ pinMode(A_PIN, OUTPUT);
+ pinMode(B_PIN, OUTPUT);
+ pinMode(C_PIN, OUTPUT);
+ pinMode(D_PIN, OUTPUT);
+ pinMode(E_PIN, OUTPUT);
+ pinMode(F_PIN, OUTPUT);
+ pinMode(G_PIN, OUTPUT);
+ pinMode(DP_PIN, OUTPUT);
+ digitalWrite(A_PIN, HIGH);
+ digitalWrite(B_PIN, HIGH);
+ digitalWrite(C_PIN, HIGH);
+ digitalWrite(D_PIN, HIGH);
+ digitalWrite(E_PIN, HIGH);
+ digitalWrite(F_PIN, HIGH);
+ digitalWrite(G_PIN, HIGH);
+ digitalWrite(DP_PIN, HIGH);
+}
+
+void loop()
+{
+ for (uint8_t cnt = 0; cnt < 16; cnt++)
+ {
+ print_digit(cnt);
+ delay(1000);
+ }
+}
+
+int print_digit(uint8_t digit)
+{
+ if (digit > 15)
+ {
+ return -1;
+ }
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ digitalWrite(pins[i], segment_map[digit] & (128 >> i));
+ }
+
+ return 0;
+}
--- /dev/null
+#define LATCH_PIN 4
+#define CLK_PIN 7
+#define SDI_PIN 8
+
+int print_digit(uint8_t segment, uint8_t value);
+
+// Segment map to select number 0 to F
+const uint8_t SEGMENT_MAP[16] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
+// Byte map to select digit 0 to 3
+const uint8_t SEGMENT_SELECT[4] = {0xF1, 0xF2, 0xF4, 0xF8};
+
+void setup()
+{
+ pinMode(LATCH_PIN, OUTPUT);
+ pinMode(CLK_PIN, OUTPUT);
+ pinMode(SDI_PIN, OUTPUT);
+ digitalWrite(LATCH_PIN, LOW);
+ digitalWrite(CLK_PIN, LOW);
+ digitalWrite(SDI_PIN, LOW);
+}
+
+void loop()
+{
+ print_digit(0, 5);
+ print_digit(1, 6);
+ print_digit(2, 7);
+ print_digit(3, 9);
+}
+
+/* Write a decimal number between 0 and 9 to one of the 4 digits of the display */
+int print_digit(uint8_t segment, uint8_t value)
+{
+ if (value > 15 || segment > 3)
+ {
+ return -1;
+ }
+
+ shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_MAP[value]);
+ shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_SELECT[segment] );
+ digitalWrite(LATCH_PIN, HIGH);
+ digitalWrite(LATCH_PIN, LOW);
+
+ return 0;
+}