const int leds[] = { 13 , 12 , 11 , 10 , 9 , 8 , 7 , 6 , 5};
const int ledStripSize = sizeof(leds) / sizeof(leds[0]);
const int rows = 3;
const int cols = 3;
int posX = 0;
int posY = 0;
//creating a static array since dynamic arrays are not allow
int ledMatrix[rows][cols];
void setup() {
Serial.begin(9600);
for(int i = 0 ; i < ledStripSize ; i++ ){
pinMode(leds[i] , OUTPUT);
}
//assigning
int counter = 0;
while(counter < ledStripSize){
for(int x = 0; x < rows ; x++ ) {
for(int y = 0 ; y < cols ; y++){
ledMatrix[x][y] = leds[counter];
// Serial.println(ledMatrix[x][y]);
counter++;
}
}
}
// blink(1000);
}
void loop() {
int H[7][2] = {
{0,0} , { 1 , 0 } , { 2 , 0} ,
{ 1 , 1 } ,
{0,2} , { 1 , 2 } , { 2 , 2}
};
int I[7][2] = {
{0,0} , { 0 , 1} , { 0 , 2},
{ 1 , 1 } ,
{2,0} , { 2 , 1 } , { 2 , 2},
};
for(int i = 0 ; i < 7 ; i++){
int x = H[i][0];
int y = H[i][1];
digitalWrite(ledMatrix[x][y] , HIGH);
}
delay(1000);
for(int i = 0 ; i < ledStripSize ; i++ ){
digitalWrite(leds[i] , LOW);
}
delay(500);
for(int i = 0 ; i < 7 ; i++){
int x = I[i][0];
int y = I[i][1];
digitalWrite(ledMatrix[x][y] , HIGH);
}
delay(1000);
for(int i = 0 ; i < ledStripSize ; i++ ){
digitalWrite(leds[i] , LOW);
}
delay(1000);
}
void right(){
if(posY < cols - 1){
posY++;
}
blink(500);
}
void left(){
if(posY > 0){
posY--;
}
blink(500);
}
void up(){
if(posX > 0){
posX--;
}
blink(500);
}
void down(){
if(posX < rows - 1){
posX++;
}
blink(500);
}
void blink(int duration){
digitalWrite(ledMatrix[posX][posY] , HIGH);
delay(duration);
Serial.println("X"); Serial.println(posX);
Serial.println("Y"); Serial.println(posY);
digitalWrite(ledMatrix[posX][posY] , LOW);
delay(duration);
}
///let H