#include <LedControl.h>
#define Din 11
#define CS 10
#define CLK 13
//ON = LOW
//OFF = HIGH
#define up 7
#define down 6
#define left 5
#define right 4
LedControl lc = LedControl(Din, CLK, CS, 1);
byte x = 5, y = 5;
void moveLeft() {
if (x < 7) {
lc.setLed(0, y, x, false);
delay(50);
x++;
lc.setLed(0, y, x, true);
delay(50);
}
}
void moveRight() {
if (x > 0) {
lc.setLed(0, y, x, false);
delay(50);
x--;
lc.setLed(0, y, x, true);
delay(50);
}
}
void moveUp() {
if (y > 0) {
lc.setLed(0, y, x, false);
delay(50);
y--;
lc.setLed(0, y, x, true);
delay(50);
}
}
void moveDown() {
if (y < 7) {
lc.setLed(0, y, x, false);
delay(50);
y++;
lc.setLed(0, y, x, true);
delay(50);
}
}
void setup() {
// put your setup code here, to run once:
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(8);
Serial.begin(9600);
pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(left, INPUT);
pinMode(right, INPUT);
lc.setLed(0, y, x, true);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(up) == LOW) {
Serial.println("up pressed");
delay(50);
moveUp();
}
if (digitalRead(down) == LOW) {
Serial.println("down pressed");
delay(50);
moveDown();
}
if (digitalRead(left) == LOW) {
Serial.println("left pressed");
delay(50);
moveLeft();
}
if (digitalRead(right) == LOW) {
Serial.println("right pressed");
delay(50);
moveRight();
}
delay(50);
}