constexpr auto PinCount = 4;
int pins[PinCount] = {11, 12, 9, 10};
bool data[PinCount][PinCount-1] = {false};
void setup() {
}
void setPins(int row, int col){
if(row >= PinCount || col >= PinCount-1) return;
bool on = data[row][col];
col = (row + col) % 3;
if(col >= row) col++;
for(int x = 0; x < PinCount; x++){
if(x == row && on){
pinMode(pins[x], OUTPUT);
digitalWrite(pins[x], HIGH);
} else if ( x == col && on){
pinMode(pins[x], OUTPUT);
digitalWrite(pins[x], LOW);
} else {
pinMode(pins[x], INPUT);
digitalWrite(pins[x], LOW);
}
}
}
void loop() {
for(int y = 0; y < PinCount-1; y++){
for(int x = 0; x < PinCount; x++){
setPins(x,y);
delay(1);
}
}
updateData();
}
auto start = millis();
int r = 3;
int c = 2;
void updateData(){
auto now = millis();
if(now - start > 1000){
data[r][c] = false;
r = (r + 1)%PinCount;
if(r == 0){
c = (c + 1) % (PinCount - 1);
}
data[r][c] = true;
start = now;
}
}