//Copyright (C) 18.06.2025, Kirill ZHivotkov
/*
Игра "Color Lines".
*/
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal_I2C.h>
#include <Vector.h>
#include <limits.h>
#define R1 13 //PIN
#define G1 12 //PIN
#define B1 11 //PIN
#define R2 10 //PIN
#define G2 9 //PIN
#define B2 8 //PIN
#define R3 7 //PIN
#define G3 6 //PIN
#define B3 5 //PIN
#define PIN 4 //PIN
#define BUZZER 3 //PIN
#define RGB 7 //VALUE
#define SIZE 8 //VALUE
#define START 10 //VALUE
#define NEW 3 //VALUE
#define MIN 3 //VALUE
#define MOVE 512 //VALUE
#define SLEEP 0 //VALUE
#define SPEED 200 //VALUE
#define BLACK 16777215
#define CYAN 65535
#define RED 65280
#define GREEN 16711680
#define MAGENTA 16711935
#define BLUE 255
#define YELLOW 16776960
#define ORANGE 16744192
#define XJ1 A0 //PIN
#define YJ1 A1 //PIN
#define SW1 A2 //PIN
//Declare matrix class variable
Adafruit_NeoPixel pixels(SIZE * SIZE, PIN);
//Declare matrix class variable
//Declare display class variable
LiquidCrystal_I2C lcd(39, 16, 2); //Address = 39
//Declare display class variable
struct Color {
int r;
int g;
int b;
};
struct Coord {
int x;
int y;
Color c;
};
int p_x = 0;
int p_y = 0;
static int blinkCounter = 0;
static int lastBallBlinkingCheck = 0;
static int gameScorePoints = 0;
bool isError = false;
bool isSelected = false;
bool isBlinking = false;
bool isOverTheBall = false;
bool isRemoved = false;
char maze[SIZE][SIZE] = { //Empty field
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'}
};
Coord ball;
Coord start = {-1, -1, {0, 0, 0}};
Coord finish = {-1, -1, {0, 0, 0}};
Coord storage[SIZE * SIZE] = {};
Vector<Coord> v(storage, SIZE * SIZE);
Color colors[RGB] = {{0, UCHAR_MAX, UCHAR_MAX /*Cyan*/},
{0, UCHAR_MAX, 0 /*Green*/},
{UCHAR_MAX, 0, 0 /*Red*/},
{UCHAR_MAX, 0, UCHAR_MAX /*Magenta*/},
{0, 0, UCHAR_MAX /*Blue*/},
{UCHAR_MAX, UCHAR_MAX, 0 /*Yellow*/},
{UCHAR_MAX, UCHAR_MAX / 2, 0 /*Orange*/}};
Color c[MIN];
void setup() {
Serial.println("\nSetup call (possible crash)");
Serial.begin(9600);
//Link RGB LEDS
pinMode(R1, OUTPUT);
pinMode(G1, OUTPUT);
pinMode(B1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(G2, OUTPUT);
pinMode(B2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(G3, OUTPUT);
pinMode(B3, OUTPUT);
//Link RGB LEDS
pixels.begin();
pixels.setBrightness(UCHAR_MAX);
//Link buzzer
pinMode(BUZZER, OUTPUT);
//Link buzzer
//Link joystick
pinMode(XJ1, INPUT);
pinMode(YJ1, INPUT);
pinMode(SW1, INPUT);
//Link joystick
//Shuffle decks and colors (primarily for the random set)
randomSeed(micros());
ShuffleColors(colors, RGB);
//Shuffle decks and colors (primarily for the random set)
//Set the initial led position (black one in the left top corner)
pixels.setPixelColor(0, pixels.Color(UCHAR_MAX, UCHAR_MAX, UCHAR_MAX));
pixels.show();
//Set the initial led position (black one in the left top corner)
//Clear vectors initialized with zeroes
v.clear();
//Clear vectors initialized with zeroes
//Generate random ball set with the number of balls specified
GenerateRandomBallSet(START);
ShowBallsOnBFSGrid();
//Generate random ball set with the number of balls specified
//Switch on next balls color hints
SwitchOnNextBallsColorHints();
//Switch on next balls color hints
//Link display
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("SCORE: ");
lcd.setCursor(0, 1);
lcd.print("BALLS: ");
//Link display
DisplayGameScore(0);
DisplayNumberOfBalls();
}
//Set RGB LED color (next 3 random balls distribution)
void RGBLedColor(int r, int g,int b, int r_value, int g_value, int b_value) {
analogWrite(r, r_value);
analogWrite(g, g_value);
analogWrite(b, b_value);
}
//Set RGB LED color (next 3 random balls distribution)
//BFS
int dRow[] = {-1, 1, 0, 0};
int dCol[] = {0, 0, -1, 1};
typedef struct {
int x, y;
int dist;
} QueueNode;
bool isValid(int row, int col, bool visited[SIZE][SIZE], char grid[SIZE][SIZE]) {
return (row >= 0 && row < SIZE && col >= 0 && col < SIZE && grid[row][col] == '.' && !visited[row][col]);
}
int bfs(char grid[SIZE][SIZE], int xStart, int yStart, int xEnd, int yEnd) {
bool visited[SIZE][SIZE] = {false};
QueueNode queue[SIZE * SIZE];
int front = 0, rear = 0;
queue[rear++] = (QueueNode){xStart, yStart, 0};
visited[xStart][yStart] = true;
while (front < rear) {
QueueNode current = queue[front++];
if (current.x == xEnd && current.y == yEnd) {
return current.dist;
}
for (int i = 0; i < 4; i++) {
int newRow = current.x + dRow[i];
int newCol = current.y + dCol[i];
if (isValid(newRow, newCol, visited, grid)) {
visited[newRow][newCol] = true;
queue[rear++] = (QueueNode){newRow, newCol, current.dist + 1};
}
}
}
return -1;
}
//BFS
//Move ball to another position
void BallMoveSuccess() {
maze[start.x][start.y] = '.';
maze[finish.x][finish.y] = '#';
isBlinking = false;
blinkCounter = 0;
v.remove(GetBallIndex(start.x, start.y));
pixels.setPixelColor(XY(start.x, start.y), pixels.Color(0, 0, 0));
pixels.show();
v.push_back({finish.x, finish.y, finish.c});
pixels.setPixelColor(XY(finish.x, finish.y), pixels.Color(finish.c.r, finish.c.g, finish.c.b));
pixels.show();
//tone(BUZZER, 300, 100);
}
//Move ball to another position
//Set game Score
void DisplayGameScore(int score) {
lcd.setCursor(7, 0);
lcd.print(score);
}
//Set game score
//Set number of balls
void DisplayNumberOfBalls() {
if (v.size() < SIZE * SIZE) {
lcd.setCursor(7, 1);
lcd.print(v.size());
}
}
//Set number of balls
//Set game over message
void GameOver() {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(3, 1);
lcd.print("GAME OVER!");
tone(BUZZER, 50, 200);
}
//Set game over message
//Check if a path from start to finish exists
void CheckIfPathExists(char maze[SIZE][SIZE], int x1, int y1, int x2, int y2) {
int result = bfs(maze, x1, y1, x2, y2);
if (result != -1) { //If the path to a new position exists (not blocked by the group of other balls)
Serial.println("Path exists!");
//Success of changing the ball position
BallMoveSuccess();
//Success of changing the ball position
//Call a ball line remove method (with the number of balls specified just in case is may be removed)
RemoveBallLine(MIN);
//Call a ball line remove method (with the number of balls specified just in case is may be removed)
//Create more random balls of different colors after successful move
GenerateRandomBallSet(NEW);
//Create more random balls of different colors after successful move
//Switch on next balls color hints
SwitchOnNextBallsColorHints();
//Switch on next balls color hints
DisplayNumberOfBalls();
ShowBallsOnBFSGrid();
} else {
Serial.println("No path found!");
tone(BUZZER, 100, 200);
maze[start.x][start.y] = '#';
maze[finish.x][finish.y] = '.';
DisplayNumberOfBalls();
ShowBallsOnBFSGrid();
}
}
//Check if a path from start to finish exists
//Clear a maze from the path trace
void ShowBallsOnBFSGrid() {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (maze[i][j] == 'V') {
maze[i][j] = '.';
}
Serial.print(maze[i][j]);
Serial.print(" ");
}
Serial.println();
}
}
//Clear a maze from the path trace
//Shuffle decks and their colors (template function)
template<class T>
void ShuffleColors(T arr[], int limit) {
for (int i = 0; i < limit; i++) {
int n = random(0, limit);
auto temp = arr[n];
arr[n] = arr[i];
arr[i] = temp;
}
}
//Shuffle decks and their colors (template function)
//Remove ball line horizontally
void RemoveBallSound() {
delay(100);
tone(BUZZER, 150, 50);
}
void RemoveBallLine(int qty) {
int x, y;
int k;
int bonusCounter = 0;
int lineScore = 0;
isRemoved = false;
//HOR
for (int i = 0; i < SIZE; i++) {
k = 0;
for (int j = 0; j < SIZE - 1; j++) {
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i, j + 1))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i, j + 1))) != 0) {
k++;
} else {
x = i;
y = j;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int p = y - k; p <= y; p++) {
if (x == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int p = y - k; p <= y; p++) {
v.remove(GetBallIndex(x, p));
maze[x][p] = '.';
pixels.setPixelColor(XY(x, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 10;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int p = SIZE - 1 - k; p <= SIZE - 1; p++) {
if (x == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int p = SIZE - 1 - k; p <= SIZE - 1; p++) {
v.remove(GetBallIndex(x, p));
maze[x][p] = '.';
pixels.setPixelColor(XY(x, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 10;
}
bonusCounter++;
isRemoved = true;
}
}
}
//HOR
if (isRemoved == true) {
pixels.setPixelColor(XY(finish.x, finish.y), pixels.Color(finish.c.r, finish.c.g, finish.c.b));
pixels.show();
}
//VER
for (int j = 0; j < SIZE; j++) {
k = 0;
for (int i = 0; i < SIZE - 1; i++) {
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i + 1, j))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i + 1, j))) != 0) {
k++;
} else {
x = j;
y = i;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int p = y - k; p <= y; p++) {
if (p == finish.x && x == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int p = y - k; p <= y; p++) {
v.remove(GetBallIndex(p, x));
maze[p][x] = '.';
pixels.setPixelColor(XY(p, x), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 10;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int p = SIZE - 1 - k; p <= SIZE - 1; p++) {
if (p == finish.x && x == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int p = SIZE - 1 - k; p <= SIZE - 1; p++) {
v.remove(GetBallIndex(p, x));
maze[p][x] = '.';
pixels.setPixelColor(XY(p, x), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 10;
}
bonusCounter++;
isRemoved = true;
}
}
}
//VER
if (isRemoved == true) {
pixels.setPixelColor(XY(finish.x, finish.y), pixels.Color(finish.c.r, finish.c.g, finish.c.b));
pixels.show();
}
//DIAG 1, 2
int i, j;
//DIAG 1, 2
//DIAG 1 (LEFT TOP > RIGHT BOTTOM)
for (int p = SIZE - 1; p >= 1 - SIZE; p--) {
k = 0;
if (p >= 0) {
i = -1;
for (j = p; j < SIZE; j++) {
++i;
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i + 1, j + 1))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i + 1, j + 1))) != 0) {
k++;
} else {
x = i;
y = j;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int t = x - k, p = y - k; p <= y; t++, p++) {
if (t == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int t = x - k, p = y - k; p <= y; t++, p++) {
v.remove(GetBallIndex(t, p));
maze[t][p] = '.';
pixels.setPixelColor(XY(t, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 20;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
} else if (p < 0) {
j = -1;
for (i = abs(p); i < SIZE; i++) {
++j;
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i + 1, j + 1))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i + 1, j + 1))) != 0) {
k++;
} else {
x = i;
y = j;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int t = x - k, p = y - k; p <= y; t++, p++) {
if (t == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int t = x - k, p = y - k; p <= y; t++, p++) {
v.remove(GetBallIndex(t, p));
maze[t][p] = '.';
pixels.setPixelColor(XY(t, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 20;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
}
}
//DIAG 1 (LEFT TOP > RIGHT BOTTOM)
if (isRemoved == true) {
pixels.setPixelColor(XY(finish.x, finish.y), pixels.Color(finish.c.r, finish.c.g, finish.c.b));
pixels.show();
}
//DIAG 2 (RIGHT TOP > LEFT BOTTOM)
for (int p = SIZE - 1; p >= 1 - SIZE; p--) {
k = 0;
if (p > 0) {
i = -1;
for (j = SIZE - p - 1; j >= 0; j--) {
++i;
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i + 1, j - 1))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i + 1, j - 1))) != 0) {
k++;
} else {
x = i;
y = j;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int t = x, p = y; t >= x - k; t--, p++) {
if (t == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int t = x, p = y; t >= x - k; t--, p++) {
v.remove(GetBallIndex(t, p));
maze[t][p] = '.';
pixels.setPixelColor(XY(t, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 20;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
} else if (p <= 0) {
j = SIZE;
for (i = abs(p); i < SIZE; i++) {
--j;
if (pixels.getPixelColor((XY(i, j))) == pixels.getPixelColor((XY(i + 1, j - 1))) && pixels.getPixelColor((XY(i, j))) != 0 && pixels.getPixelColor((XY(i + 1, j - 1))) != 0) {
k++;
} else {
x = i;
y = j;
if (k >= qty - 1) {
bool lineGoesThoughFinish = false;
for (int t = x, p = y; t >= x - k; t--, p++) {
if (t == finish.x && p == finish.y) {
lineGoesThoughFinish = true;
}
}
if (lineGoesThoughFinish == true) {
for (int t = x, p = y; t >= x - k; t--, p++) {
v.remove(GetBallIndex(t, p));
maze[t][p] = '.';
pixels.setPixelColor(XY(t, p), pixels.Color(0, 0, 0));
pixels.show();
RemoveBallSound();
lineScore += 20;
}
bonusCounter++;
isRemoved = true;
}
}
k = 0;
}
}
}
}
//DIAG 2 (RIGHT TOP > LEFT BOTTOM)
if (isRemoved == true) {
pixels.setPixelColor(XY(finish.x, finish.y), pixels.Color(0, 0, 0));
pixels.show();
}
//Set game score
if (bonusCounter >= 1) {
gameScorePoints += bonusCounter * lineScore;
DisplayGameScore(gameScorePoints);
}
//Set game score
}
//Remove ball line horizontally
//Clear game field
void ClearGameField() {
for (int i = 0; i < v.size(); i++) {
pixels.setPixelColor(XY(v[i].x, v[i].y), pixels.Color(0, 0, 0));
pixels.show();
}
}
//Clear game field
//Get blinking ball index
int GetBallIndex(int x, int y) {
for (int j = 0; j < v.size(); j++) {
if (v[j].x == x && v[j].y == y) {
return j;
}
}
return -1;
}
//Get blinking ball index
//Draw all balls at once
void DrawBalls() {
for (int i = 0; i < v.size(); i++) {
pixels.setPixelColor(XY(v[i].x, v[i].y), pixels.Color(v[i].c.r, v[i].c.g, v[i].c.b));
pixels.show();
}
}
//Draw all balls at once
//Check if one ball does not overlap with another
void ResetBallAfterOverlap(int x, int y, int color) {
for (int j = 0; j < v.size(); j++) {
if ((v[j].x == x) && (v[j].y == y)) {
Serial.println("OVERLAPPED!");
delay(SLEEP);
isError = true;
}
}
}
//Check if one ball does not overlap with another
//Set a random ball RGB color
void SwitchOnNextBallsColorHints() {
c[0] = colors[random(0, RGB)];
c[1] = colors[random(0, RGB)];
c[2] = colors[random(0, RGB)];
RGBLedColor(R1, G1, B1, c[0].r, c[0].g, c[0].b);
RGBLedColor(R2, G2, B2, c[1].r, c[1].g, c[1].b);
RGBLedColor(R3, G3, B3, c[2].r, c[2].g, c[2].b);
}
//Set a random ball RGB color
//Set a random ball RGB color
void SetBallRGBColor(int x, int y, int index, int qty, int i) {
ball.x = x;
ball.y = y;
if (qty == MIN) {
ball.c = c[i];
} else {
ball.c = colors[index];
}
v.push_back(ball);
pixels.setPixelColor(XY(x, y), pixels.Color(ball.c.r, ball.c.g, ball.c.b));
pixels.show();
}
//Set a random ball RGB color
//Set a random ball position
void SetRandomBallPosition(int x, int y, int color, int qty, int i) {
isError = false;
ResetBallAfterOverlap(x, y, color);
if (isError == false) {
SetBallRGBColor(x, y, color, qty, i);
maze[x][y] = '#';
Serial.println("OK!");
}
}
//Set a random ball position
//Set player free move
void SetPlayerFreeMove() {
if (pixels.getPixelColor(XY(p_x, p_y)) != CYAN &&
pixels.getPixelColor(XY(p_x, p_y)) != GREEN &&
pixels.getPixelColor(XY(p_x, p_y)) != RED &&
pixels.getPixelColor(XY(p_x, p_y)) != MAGENTA &&
pixels.getPixelColor(XY(p_x, p_y)) != BLUE &&
pixels.getPixelColor(XY(p_x, p_y)) != YELLOW &&
pixels.getPixelColor(XY(p_x, p_y)) != ORANGE) {
pixels.setPixelColor(XY(p_x, p_y), pixels.Color(0, 0, 0));
pixels.show();
}
}
//Set player free move
//Set ball start position
void SetBallStartPosition() {
if (pixels.getPixelColor(XY(p_x, p_y)) != 0) {
DrawBalls();
Serial.println("OVER");
isOverTheBall = true;
pixels.setPixelColor(XY(p_x, p_y), pixels.Color(UCHAR_MAX, UCHAR_MAX, UCHAR_MAX));
pixels.show();
} else {
DrawBalls();
Serial.println("FREE");
isOverTheBall = false;
pixels.setPixelColor(XY(p_x, p_y), pixels.Color(UCHAR_MAX, UCHAR_MAX, UCHAR_MAX));
pixels.show();
}
}
//Set ball start position
//Set a player joystick control
void PlayerJoystickControl() {
//Confirm start of finish
if ((analogRead(SW1) == 0) && (isSelected == false) && (isOverTheBall == true)) {
DrawBalls();
isSelected = true;
Serial.println("Start!");
isBlinking = true;
blinkCounter = 0;
start = v[GetBallIndex(p_x, p_y)];
pixels.setPixelColor(XY(p_x, p_y), pixels.Color(start.c.r, start.c.g, start.c.b));
pixels.show();
} else if ((analogRead(SW1) == 0) && (isSelected == false) && (isOverTheBall == false) && (isBlinking == true)) {
isSelected = true;
Serial.println("Finish!");
finish.x = p_x;
finish.y = p_y;
finish.c = start.c;
CheckIfPathExists(maze, start.x, start.y, finish.x, finish.y);
}
//Confirm start of finish
//Joystick control
int x = analogRead(A1);
int y = analogRead(A0);
if (x == 2 * MOVE - 1 && y == MOVE) { //LEFT
if (p_y >= 1) {
isSelected = false;
SetPlayerFreeMove();
p_y--;
SetBallStartPosition();
}
delay(SPEED);
} else if (x == 0 && y == MOVE) { //RIGHT
if (p_y < SIZE - 1) {
isSelected = false;
SetPlayerFreeMove();
p_y++;
SetBallStartPosition();
}
delay(SPEED);
} else if (y == 2 * MOVE - 1 && x == MOVE) { //DOWN
if (p_x < SIZE - 1) {
isSelected = false;
SetPlayerFreeMove();
p_x++;
SetBallStartPosition();
}
delay(SPEED);
} else if (y == 0 && x == MOVE) { //UP
if (p_x >= 1) {
isSelected = false;
SetPlayerFreeMove();
p_x--;
SetBallStartPosition();
}
delay(SPEED);
}
//Joystick control
}
//Set a player joystick control
//Generate a random multi-colored field with ships (according to the Naval Clash game rules)
void GenerateRandomBallSet(int qty) {
for (int i = 0; i < qty; i++) {
SetRandomBallPosition(random(0, SIZE), random(0, SIZE), random(0, RGB), qty, i);
if (isError == true) {
i--;
}
if (v.size() == SIZE * SIZE) {
GameOver();
break;
}
}
Serial.println("ALL BALLS SET!");
}
//Generate a random multi-colored field with ships (according to the Naval Clash game rules
//Program loop
void loop() {
randomSeed(micros());
PlayerJoystickControl();
//Separate thread for the blinking ball
lastBallBlinkingCheck = 0;
if (millis() - lastBallBlinkingCheck > 500) {
lastBallBlinkingCheck = millis();
if (isBlinking == true) {
if (blinkCounter % 2 == 0) {
pixels.setPixelColor(XY(start.x, start.y), pixels.Color(0, 0, 0));
pixels.show();
blinkCounter++;
} else {
pixels.setPixelColor(XY(start.x, start.y), pixels.Color(start.c.r, start.c.g, start.c.b));
pixels.show();
blinkCounter++;
}
}
}
//Separate thread for the blinking ball
/*
pixels.setPixelColor(0 + 0 * SIZE, pixels.Color(0, UCHAR_MAX, UCHAR_MAX));
Serial.println(pixels.getPixelColor(0 + 0 * SIZE));
pixels.setPixelColor(1 + 0 * SIZE, pixels.Color(0, UCHAR_MAX, 0));
Serial.println(pixels.getPixelColor(1 + 0 * SIZE));
pixels.setPixelColor(2 + 0 * SIZE, pixels.Color(UCHAR_MAX, 0, 0));
Serial.println(pixels.getPixelColor(2 + 0 * SIZE));
pixels.setPixelColor(3 + 0 * SIZE, pixels.Color(UCHAR_MAX, 0, UCHAR_MAX));
Serial.println(pixels.getPixelColor(3 + 0 * SIZE));
pixels.setPixelColor(4 + 0 * SIZE, pixels.Color(0, 0, UCHAR_MAX));
Serial.println(pixels.getPixelColor(4 + 0 * SIZE));
pixels.setPixelColor(5 + 0 * SIZE, pixels.Color(UCHAR_MAX, UCHAR_MAX, 0));
Serial.println(pixels.getPixelColor(5 + 0 * SIZE));
pixels.setPixelColor(6 + 0 * SIZE, pixels.Color(UCHAR_MAX, UCHAR_MAX / 2, 0));
Serial.println(pixels.getPixelColor(6 + 0 * SIZE));
delay(60000 * 5);
*/
}
//Program loop
//LED coordinate transform (different from the real one)
int XY(int x, int y) {
return y + SIZE * x;
}
//LED coordinate transform (different from the real one)