const int dataPin = 8; // DS
const int latchPin = 9; // STCP
const int clockPin = 10; // SHCP
void setup() {
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
// Turn on the LED at position (1,1)
clearLEDs(); // First, clear the display
//setLED(1, 1, HIGH); // Set the LED at position (1,1) to ON
// No need to call refreshDisplay() since setLED() already updates the display
delay(1000); // Keep the LED on for 1000 milliseconds (1 second)
}
void clearLEDs() {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0x00); // Clear columns
shiftOut(dataPin, clockPin, MSBFIRST, 0x00); // Clear rows
digitalWrite(latchPin, HIGH);
}
void setLED(int row, int col, boolean state) {
byte rowBit = 0x01 << row; // Determine the row bit to turn on
byte colBit = ~(0x01 << col); // Determine the column bit to turn on, invert because common anode
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, colBit); // Set columns
shiftOut(dataPin, clockPin, MSBFIRST, rowBit); // Set rows
digitalWrite(latchPin, HIGH);
}
void shiftRegisterWrite(byte data) {
// Function to write data to a shift register
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}