#include <LedControl.h>
LedControl lc = LedControl(11, 13, 10, 1);
int right = 2;
int left = 4;
int up = 3;
int bottom = 5;
int x = 0, y = 0;
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
if (keys() == 1) {
x -= 1;
delay(250);
lc.setLed(0, x + 1, y, 0);
}
else if (keys() == 2) {
x += 1;
delay(250);
lc.setLed(0, x - 1, y, 0);
}
else if (keys() == 3) {
y += 1;
delay(250);
lc.setLed(0, y - 1, y, 0);
}
else if (keys() == 4) {
y -= 1;
delay(250);
lc.setLed(0, y - 1, y, 0);
}
lc.setLed(0, x, y, 1);
}
int keys() {
if (digitalRead(right)) {
return 1;
}
else if (digitalRead(left)) {
return 2;
}
else if (digitalRead(up)) {
return 3;
}
else if (digitalRead(bottom)) {
return 4;
}
return 0;
}