#include <MD_MAX72xx.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 brake 12
#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2
//
const int yLeft[] = {3, 2, 1, 0, 0};
const int yRight[] = {2, 3, 4, 5, 5};
const int lineLeft[] = {7, 6, 5, 4, 3};
const int lineRight[] = {0, 1, 2, 3, 4};
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);
int x = 0;
int y = 0;
void setup() {
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
mx.clear();
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
pinMode(brake, INPUT_PULLUP);
pinMode(3, OUTPUT);
}
void setArrow(int y[], int line[]) {
mx.clear();
const int x[] = {0, 1, 2, 3, 3};
const int x2[] = {7, 6, 5, 4, 4};
for (int i = 0; i < 5; i++) {
mx.setPoint(x[i], y[i], true);
mx.setPoint(x2[i], y[i], true);
mx.setPoint(x[i], y[i] + 1, true);
mx.setPoint(x2[i], y[i] + 1, true);
mx.setPoint(x[i], y[i] + 2, true);
mx.setPoint(x2[i], y[i] + 2, true);
delay(100);
mx.setPoint(3, line[i], true);
mx.setPoint(4, line[i], true);
}
}
void logo() {
mx.clear();
for (int i = 7; i >= 0; i--) {
if (i >= 1 && i < 6) {
mx.setPoint(i, 0, true);
mx.setPoint(i, 1, true);
mx.setPoint(i, 6, true);
mx.setPoint(i, 7, true);
}
if(i > 3){
// mx.setPoint(i, 3, true);
// mx.setPoint(i, 4, true);
}
// mx.setPoint(0, i, true);
// mx.setPoint(1, i, true);
delay(20);
}
}
// the loop function runs over and over again forever
void loop() {
while(digitalRead(brake) == LOW){
mx.clear();
logo();
digitalWrite(3, HIGH);
delay(20);
digitalWrite(3, LOW);
}
int horz = analogRead(HORZ_PIN);
int vert = analogRead(VERT_PIN);
if (vert < 300) {
logo();
}
if (vert > 700) {
setArrow(yLeft, lineLeft);
}
if (horz > 700) {
setArrow(yRight, lineRight);
}
if (horz < 300) {
setArrow(yLeft, lineLeft);
}
if (digitalRead(SEL_PIN) == LOW) {
mx.clear();
}
mx.update();
delay(100);
}