const uint8_t PIN_DS = 2;
const uint8_t PIN_SHCP = 4;
const uint8_t PIN_STCP = 3;
void send(uint16_t data) {
digitalWrite(PIN_STCP, LOW);
shiftOut(PIN_DS, PIN_SHCP, LSBFIRST, (data >> 8) & 0xFF); // górny chip
shiftOut(PIN_DS, PIN_SHCP, LSBFIRST, data & 0xFF); // dolny chip
digitalWrite(PIN_STCP, HIGH);
digitalWrite(PIN_STCP, LOW);
}
void setup() {
pinMode(PIN_DS, OUTPUT);
pinMode(PIN_SHCP, OUTPUT);
pinMode(PIN_STCP, OUTPUT);
// Test: zapal wszystkie 16 LEDów
send(0xFFFF);
delay(1000);
// Test: zapal co drugi
send(0xAAAA);
delay(1000);
send(0x5555);
delay(1000);
}
void loop() {
// Knight Rider na 16 LEDach
for (int i = 0; i < 16; i++) {
send((uint16_t)1 << i);
delay(60);
}
for (int i = 14; i > 0; i--) {
send((uint16_t)1 << i);
delay(60);
}
}