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);
TCCR1A = 0; // Init Timer1A
TCCR1B = 0; // Init Timer1B
TCCR1B |= B00000001; // Prescaler = 1
OCR1A = 16000; // Timer Compare1A Register
TIMSK1 |= B00000010; // Enable Timer COMPA Interrupt
}
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 pattern [2][5] = { { 0b0010000011110111,
0b0110000011101111,
0b0010000011011111,
0b0010000010111111,
0b0111000001111111 },
{ 0b0110000011110111,
0b1001000011101111,
0b0010000011011111,
0b0100000010111111,
0b1111000001111111 } };
void loop() {
for(uint8_t i=0;i<5;i++)
{ digitalWrite(latchPin, LOW);
shiftOutManual(dataPin, clockPin, pattern[1][i]);
digitalWrite(latchPin, HIGH);
delay(5);
}
delay(500);
}
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);
}
}
ISR(TIMER1_COMPA_vect)
{ OCR1A += 16000; // Advance The COMPA Register
}