#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
//------------ DEFINIRANJE NA BOITE --------------------------------
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//----------------------------------------------------------------------------
//--------- definiranje parametri za matricata ----------------------
int matrixW = 8; //dolzina na matrica
int matrixH = 8; //sirina na matrica
#define PIN 6 // //pino na koj sme povrzani
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(matrixW, matrixH, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
//kazuvame deka ke pocneme od gore levo ,ke odi po redici ,PROGRESSIVE sekogas mora
//inace ne se cita
uint16_t textColor = matrix.Color(255, 0, 0); // boja na matricata
const uint16_t drawingColors[] = { GREEN, BLUE, CYAN, WHITE, RED};
// 3 boi za pravoagolnicite
#define arr_len( x ) ( sizeof( x ) / sizeof( *x ) )
int pixelPerChar = 6; // goleminata na eden karakter
int x = matrix.width(); // dolzina na display
int pass = 0; // Counter
int i = 0; // Counter
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255); //postavuvanje na osvetlenost
matrix.setTextColor(textColor); // boja na textot (mora od tuka da se postavi)
}
void loop() {
writeText("prvo"); //pisuvame text koj se dvizi (f-jata e dole)
drawRectangles(); // nacrtaj pravoagolnicite
matrix.show();
delay(500);
/*зада е статичен текстот се користи matrix.print();
char msgText[] = "Let's Start Over";
matrix.fillScreen(0); // Чистење на екранот
matrix.setCursor(0, 0); // Поставување на курсорот на почеток
matrix.print(msgText); // Печатење на статичен текст
matrix.show();
delay(1000);
*/
writeText("vtoro"); // pisuvame text za kraj
drawLines();
matrix.show();
delay(500);
writeText("kraj");
}
/* -------------------- funkcija za pisuvanje text -------------------- */
void writeText(String msg) {
int msgSize = (msg.length() * pixelPerChar) + (2 * pixelPerChar); // Calculate message length
int scrollingMax = (msgSize) + matrix.width(); // Adjust displacement for message length
x = matrix.width(); // Reset cursor position and start text string at new position on the far right
while (true) {
matrix.setTextColor(textColor); // Set the text color
matrix.fillScreen(0); // Blank the entire screen
matrix.setCursor(x, 0); // Set starting point for text string
matrix.print(msg); // Set the message string
// Scroll text from right to left by moving the cursor position
if (--x < -scrollingMax) {
// Adjust for message length
// Decrement x by one and compare new value of x to -scrollingMax;
// This animates (moves) the text by one pixel to the left
x = matrix.width(); // After scrolling by scrollingMax pixels, reset cursor position and start string at new position on the far right
break; // Exit the loop after one complete scroll
}
matrix.show(); // Display the text/image
delay(200); // Speed of scrolling or frame rate
}
}
void drawRectangles() { // f-ja za crtanje na kvadradcinja od najgolem do najmal
matrix.fillScreen(0);
for (int i = 0; i < matrix.width() / 2; i++) {
matrix.drawRect(i, i, matrix.width() - i * 2 , matrix.width() - i * 2 , drawingColors[i+1]);
matrix.show();
delay(200);
}
}
void drawLines() { //funkcija za crtanje na snegulkata
matrix.fillScreen(0);
matrix.drawLine(0, 0, 7, 7, BLUE);
matrix.show();
delay(200);
matrix.drawLine(7, 0, 0, 7, YELLOW);
matrix.show();
delay(200);
matrix.drawLine(4, 0, 4, 7, RED);
matrix.show();
delay(200);
matrix.drawLine(0, 3, 7, 3, WHITE);
matrix.show();
delay(200);
}