// Number of pins
#define NUM_PINS 20
// Up, down, left, right
uint8_t PIN_MOVEMENT[][4] {
// Top row
{0, 13, 0, 10},
{0, 12, 11, 9},
{0, A0, 10, 8},
{0, A1, 9, 7},
{0, A2, 8, 6},
{0, A3, 7, 5},
{0, A4, 6, 4},
{0, A5, 5, 3},
{0, A6, 4, 2},
{0, A7, 3, 0},
// Bottom row
{11, 0, 0, 13},
{10, 0, 12, A0},
{9, 0, 13, A1},
{8, 0, A0, A2},
{7, 0, A1, A3},
{6, 0, A2, A4},
{5, 0, A3, A5},
{4, 0, A4, A6},
{3, 0, A5, A7},
{2, 0, A6, 0},
};
// Top to bottom, left to right
uint8_t PIN_MAPPING[] {
11,10,9,8,7,6,5,4,3,2,
12,13,A0,A1,A2,A3,A4,A5,A6,A7
};
// Stores current state of front and back buffers
uint8_t state[][NUM_PINS] {
{0,1,0,1,0,1,0}, {1,0,1,0,1,0,1,0}
};
bool buffer = 0;
void updateLEDs() {
for (uint8_t i=0; i<NUM_PINS; i++) {
Serial.print(state[buffer][i], DEC);
digitalWrite(PIN_MAPPING[i], state[buffer][i]);
}
Serial.println();
}
void setup() {
Serial.begin(115200);
for (uint8_t i=0; i<NUM_PINS; i++) {
pinMode(PIN_MAPPING[i], OUTPUT);
digitalWrite(PIN_MAPPING[i], LOW);
}
}
void loop() {
buffer = !buffer;
updateLEDs();
delay(500);
}