#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 CLK_PIN2 5
#define DATA_PIN2 3
#define CS_PIN2 4
#define VERT_PIN A0
#define HORZ_PIN A1
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);
LedControl lc = LedControl(DATA_PIN2, CLK_PIN2, CS_PIN2, 0);
int x = 0;
int y = 0;
int mas[32][2] = {
{2, 0}, {5, 0},
{7, 0}, {1, 1},
{2, 1}, {3, 1},
{5, 1}, {7, 1},
{1, 2}, {2, 2},
{7, 2}, {2, 3},
{4, 3}, {5, 3},
{7, 3}, {0, 4},
{5, 4}, {7, 4},
{0, 5}, {1, 5},
{3, 5}, {5, 5},
{7, 5}, {1, 6},
{3, 6}, {5, 6},
{7, 6}, {1, 7},
{2, 7}, {3, 7},
{5, 7}, {7, 7}
};
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);
pinMode(6, OUTPUT);
}
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 = max(x - 1, 0);
}
if (horz < 300) {
x = min(x + 1, maxX);
}
labirint();
if (isWall(x, y)){
mx.clear();
x = 0;
y = 0;
mx.setPoint(x, y, true);
mx.update();
} else {
mx.clear();
mx.setPoint(x, y, true);
if(x == 6 && y == 7){
digitalWrite(6, HIGH);
}
digitalWrite(6, LOW);
// mx.update();
}
delay(100);
}
bool isWall(int x, int y){
for(int i = 0; i < 32; i++){
if (x == mas[i][0] && y == mas[i][1]){
return true;
}
}
return false;
}
void labirint(){
for(int i = 0; i < 32; i++){
lc.setLed(0, mas[i][0], mas[i][1], true);
}
}