#include <Arduino.h>
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 23 is connected to the DataIn
pin 18 is connected to the CLK
pin 15 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(23,18,15,1);
#define NAVE 18 // Numarul de LED uri alocate navelor
int dr_sg = 0;
int sus_jos = 0;
int nimerit_r[NAVE] = {};
int nimerit_c[NAVE] = {};
int nava_r[NAVE] = {0, 0, 0, 2, 3, 4, 6, 6, 7, 1, 2, 3, 4, 7, 0, 0, 5, 5};
int nava_c[NAVE] = {0, 1, 2, 1, 1, 1, 0, 3, 3, 4, 4, 4, 4, 5, 6, 7, 6, 7};
int end = 0;
int pinStanga = 27;
int pinSus = 13;
int pinDreapta = 12;
int pinJos = 26;
int pinConfirm = 14;
void setup() {
Serial.begin(115200);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
pinMode(pinStanga, INPUT_PULLUP);
pinMode(pinSus, INPUT_PULLUP);
pinMode(pinDreapta, INPUT_PULLUP);
pinMode(pinJos, INPUT_PULLUP);
pinMode(pinConfirm, INPUT_PULLUP);
}
void start(int r, int c){
lc.setLed(0, r, c, true);
delay(150);
lc.setLed(0, r, c, false);
delay(150);
}
void loop() {
int sg = digitalRead(pinStanga);
int sus = digitalRead(pinSus);
int dr = digitalRead(pinDreapta);
int jos = digitalRead(pinJos);
int confirm = digitalRead(pinConfirm);
start(dr_sg, sus_jos);
for(int i = 0; i < NAVE; i++){
lc.setLed(0, nimerit_r[i], nimerit_c[i], true);
}
if(end == NAVE){
lc.clearDisplay(0);
delay(50000);
}
if(sg == LOW){
Serial.println("Stanga");
sus_jos--;
if(dr_sg == -1){
dr_sg = 7;
}
}
if(sus == LOW){
Serial.println("Sus");
dr_sg--;
if(sus_jos == -1){
sus_jos = 7;
}
}
if(dr == LOW){
Serial.println("Dreapta");
sus_jos++;
if(dr_sg == 8){
dr_sg = 0;
}
}
if(jos == LOW){
Serial.println("Jos");
dr_sg++;
if(sus_jos == 8){
sus_jos = 0;
}
}
if(confirm == LOW){
Serial.println("Confirm");
for(int i = 0; i < NAVE; i++){
if(dr_sg == nava_r[i] && sus_jos == nava_c[i]){
lc.setLed(0, dr_sg, sus_jos, true);
nimerit_r[i] = dr_sg;
nimerit_c[i] = sus_jos;
end++;
}
}
dr_sg = sus_jos = 0;
}
}