const int dataPin = 2; /* DS */
const int clockPin = 3; /* SHCP */
const int latchPin = 4; /* STCP */
void setup() {
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
}
int cnt=0;
// 0b 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
// C1 C2 C3 C4 NC NC NC NC R5 R4 R3 R2 R1 NR NR NR
int16_t pattern1 = 0b0010000011110111;
int16_t pattern2 = 0b0110000011101111;
int16_t pattern3 = 0b0010000011011111;
int16_t pattern4 = 0b0010000010111111;
int16_t pattern5 = 0b0111000001111111;
void loop() {
digitalWrite(latchPin, LOW);
if(cnt==0) shiftOutManual(dataPin, clockPin, pattern1);
if(cnt==1) shiftOutManual(dataPin, clockPin, pattern2);
if(cnt==2) shiftOutManual(dataPin, clockPin, pattern3);
if(cnt==3) shiftOutManual(dataPin, clockPin, pattern4);
if(cnt==4) shiftOutManual(dataPin, clockPin, pattern5);
digitalWrite(latchPin, HIGH);
delay(5);
cnt++;
if(cnt==5) cnt=0;
}
void shiftOutManual(int dataPin, int clockPin, uint16_t val) {
for (int i = 0; i < 16; i++) {
int bit = val & (1 << i); // Get the bit at position 'i'
digitalWrite(dataPin, bit != 0 ? HIGH : LOW); // Set dataPin HIGH if bit is 1, else LOW
// Pulse the clock pin
digitalWrite(clockPin, HIGH);
delayMicroseconds(1); // short delay to ensure the clock pulse is registered
digitalWrite(clockPin, LOW);
}
}