#include <MD_MAX72xx.h>
#include <LedControl.h>
#define MAX_DEVICES 1
const int maxX = MAX_DEVICES * 8 - 1;
const int maxY = 7;
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
#define VERT_PIN A0
#define HORZ_PIN A1
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);
int x = 7;
int y = 0;
LedControl lc = LedControl(DATA_PIN, CLK_PIN, CS_PIN, 0);
byte labirint[8] = {
B00000010,
B01111010,
B01101010,
B00001000,
B11101111,
B00001000,
B01111110,
B00000000,
};
void setup() {
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
mx.clear();
lc.shutdown(0, false);
lc.setIntensity(0, 15);
lc.clearDisplay(0);
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
}
// the loop function runs over and over again forever
void loop() {
int horz = analogRead(HORZ_PIN);
int vert = analogRead(VERT_PIN);
if (vert < 300) {
y = min(y + 1, maxY);
}
if (vert > 700) {
y = max(y - 1, 0);
}
if (horz > 700) {
x = min(x + 1, maxX);
}
if (horz < 300) {
x = max(x - 1, 0);
}
mx.clear();
lc.clearDisplay(0);
displayMatrix();
lc.setLed(0, y, x, true);
// mx.setPoint(y, x, true);
mx.update();
delay(100);
}
void displayMatrix(){
for(int i = 0; i < 8; i++){
lc.setRow(0, i, labirint[i]);
}
}