// https://forum.arduino.cc/t/shift-register-code/1142032/8
#include <Adafruit_NeoPixel.h>
#define PIXPIN 2 // data pin for WS2812
#define NUMPIXELS 4 * 7 + 1 // 4 pixels/seg * 7 seg + decimal point
Adafruit_NeoPixel pixels(NUMPIXELS, PIXPIN, NEO_GRB + NEO_KHZ800);
// #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
int latchPin = 8; // ST_CP of 74HC595
int clockPin = 12;// SH_CP of 74HC595
int dataPin = 11; // DS of 74HC595
// see digit-to-decimal conversion below
int hexDigits[] = {63, 6, 91, 79, 102, 109, 125, 7, 127, 103, 119, 124, 88, 94, 121, 113};
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
led7seg();
pix7seg();
}
// **********************************************************************
// NEOPIX
// **********************************************************************
void pix7seg() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
for (int i = 0; i < 7; i++) { // segments
for (int j = 0; j < 4; j++) { // pix / segment
pixels.setPixelColor(i * 4 + j, pixels.Color(0, 255, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
delay(250);
}
pixels.setPixelColor(28, pixels.Color(0, 255, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(250);
for (int i = 0; i < 7; i++) { // segments
for (int j = 0; j < 4; j++) { // pix / segment
pixels.setPixelColor(i * 4 + j, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
pixels.setPixelColor(28, pixels.Color(0, 0, 0));
}
pixels.show(); // Send the updated pixel colors to the hardware.
delay(250);
}
void pixSeg(int seg, int state) {
for (int j = 0; j < 4; j++) { // pix / segment
pixels.setPixelColor(j * 4 + j, pixels.Color(0, 0, 0));
}
}
// **********************************************************************
// LED
// **********************************************************************
void led7seg() {
for (int i = 0; i < 16; i++) {
update595(hexDigits[i]);
delay(500);
update595(128);
delay(500);
}
}
void update595(int value)
{
digitalWrite(latchPin, LOW); // ground latchPin
shiftOut(dataPin, clockPin, MSBFIRST, value); // write the data to the data pin
digitalWrite(latchPin, HIGH); // return the latchpin high
}
/*
**************************
WS2812
**************************
SEG leds[x]
A 0 - 3
B 4 - 7
C 8 - 11
D 12 - 15
E 16 - 19
F 20 - 23
G 24 - 27
DP 28
DIG SEGMENTS
0 A, B, C, D, E, F
1 B - C 4 - 11
2 A, B, D, E, G
3 A, B, C, D, G
4 B, C, f, G
5 A, C, D, F, G
6 A, C, D, E, F, G
7 A, B, C
8 A, B, C, D, E, F, G
9 A, B, C, D, F, G
A A, B, C, E, F, G
B C, D, E, F, G
C D, E, G
D B, C, D, E, G
E A, D, E, F, G
F A, E, F, G
DP DP
**************************
7-segment LED
**************************
Bit value DEC Segment
0000 0001 = 1 = A
0000 0010 = 2 = B
0000 0100 = 4 = C
0000 1000 = 8 = D
0001 0000 = 16 = E
0010 0000 = 32 = F
0100 0000 = 64 = G
1000 0000 = 128 = DP
DIG BIN DEC HEXDIG
0 0011 1111 = 0x3F = 63
1 0000 0110 = 0x06 = 6
2 0101 1010 = 0x5A = 91
3 0100 1111 = 0x4F = 79
4 0110 0110 = 0x66 = 102
5 0110 1101 = 0x6D = 109
6 0111 1101 = 0x7D = 125
7 0000 0111 = 0x07 = 7
8 0111 1111 = 0x7F = 127
9 0110 1111 = 0x6F = 103
A 0111 0111 = 0x77 = 119
b 0111 1100 = 0x7C = 124
c 0101 1000 = 0x58 = 88
D 0101 1110 = 0x5E = 94
E 0111 1001 = 0x79 = 121
F 0111 0001 = 0x71 = 113
*/