#include <GyverMAX7219.h>
#include <Wire.h>
#define SIZE 16 // 2x2 матрицы по 8x8
MAX7219<2, 2, 5> display;
int x = 0;
int y = 0;
int vx = 0;
int vy = 0;
void setup() {
Serial.begin(115200);
display.begin(); // Инициализация матрицы
display.setBright(5); // Яркость 0..15
display.setFlip(true, false); // зеркальное отражение матриц по x
display.clear();
Serial.println("Demonstration ready");
}
bool changed = false;
void loop() {
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
int commaIndex = input.indexOf(',');
if (commaIndex != -1) {
// Парсим вектор из двух чисел
vx = input.substring(0, commaIndex).toInt();
vy = input.substring(commaIndex + 1).toInt();
}
}
// Обновляем позицию точки
x += vx;
y += vy;
// Отражение от стен
if (x < 0) {
x = 0;
vx = -vx;
changed = true;
} else if (x >= SIZE) {
x = SIZE - 1;
vx = -vx;
changed = true;
}
if (y < 0) {
y = 0;
vy = -vy;
changed = true;
} else if (y >= SIZE) {
y = SIZE - 1;
vy = -vy;
changed = true;
}
if (changed == true) {
Serial.println("Angle changed");
changed = false;
}
// Очистить дисплей и нарисовать точку
display.clear();
display.dot(x, y, true);
display.update();
delay(1000);
}