#include <MD_MAX72xx.h>
const int baris = 2;
const int kolom = 2;
#define MAX_DEVICES (baris * kolom)
const int maxX = kolom * 8;
const int maxY = 8;
struct LED {
int8_t x; // Koordinat X
int8_t y; // Koordinat Y
};
const LED HURUF_A[] = {
{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},{0,12},{0,13},{0,14},
{-1,4},{-1,10},
{-2,3},{-2,10},
{-3,2},{-3,10},
{-4,1},{-4,10},
{-5,0},{-5,10},
{-6,0},{-6,10},
{-7,1},{-7,10},
{-8,2},{-8,10},
{-9,3},{-9,10},
{-10,4},{-10,10},
{-11,5},{-11,6},{-11,7},{-11,8},{-11,9},{-11,10},{-11,11},{-11,12},{-11,13},{-11,14},
};
const uint8_t SIZE_HURUF_A = sizeof(HURUF_A) / sizeof(HURUF_A[0]);
const LED HURUF_B[] = {
{0,0},{0,14},
{-1,0},{-1,14},
{-2,0},{-2,1},{-2,2},{-2,3},{-2,4},{-2,5},{-2,6},{-2,7},{-2,8},{-2,9},{-2,10},{-2,11},{-2,12},{-2,13},{-2,14},
{-3,0},{-3,7},{-3,14},
{-4,0},{-4,7},{-4,14},
{-5,0},{-5,7},{-5,14},
{-6,0},{-6,7},{-6,14},
{-7,0},{-7,7},{-7,14},
{-8,0},{-8,7},{-8,14},
{-9,1},{-9,6},{-9,8},{-9,13},
{-10,2},{-10,5},{-10,9},{-10,12},
{-11,3},{-11,4},{-11,10},{-11,11},
};
const uint8_t SIZE_HURUF_B = sizeof(HURUF_B) / sizeof(HURUF_B[0]);
const LED HURUF_C[] = {
{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},
{-1,3},{-1,11},
{-2,2},{-2,12},
{-3,1},{-3,13},
{-4,0},{-4,14},
{-5,0},{-5,14},
{-6,0},{-6,14},
{-7,0},{-7,14},
{-8,0},{-8,14},
{-9,1},{-9,13},
{-10,2},{-10,12},
{-11,3},{-11,11}
};
const uint8_t SIZE_HURUF_C = sizeof(HURUF_C) / sizeof(HURUF_C[0]);
const LED HURUF_D[] = {
{0,0},{0,14},
{-1,0},{-1,14},
{-2,0},{-2,1},{-2,2},{-2,3},{-2,4},{-2,5},{-2,6},{-2,7},{-2,8},{-2,9},{-2,10},{-2,11},{-2,12},{-2,13},{-2,14},
{-3,0},{-3,14},
{-4,0},{-4,14},
{-5,0},{-5,14},
{-6,0},{-6,14},
{-7,0},{-7,14},
{-8,1},{-8,13},
{-9,2},{-9,12},
{-10,3},{-10,11},
{-11,4},{-11,5},{-11,6},{-11,7},{-11,8},{-11,9},{-11,10}
};
const uint8_t SIZE_HURUF_D = sizeof(HURUF_D) / sizeof(HURUF_D[0]);
const LED *getHuruf(char ch, uint8_t &size) {
switch (ch) {
case 'A':
size = SIZE_HURUF_A;
return HURUF_A;
case 'B':
size = SIZE_HURUF_B;
return HURUF_B;
case 'C':
size = SIZE_HURUF_C;
return HURUF_C;
case 'D':
size = SIZE_HURUF_D;
return HURUF_D;
default:
size = 0;
return nullptr;
}
}
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);
void tampilkanTeks(MD_MAX72XX &mx, const char *teks) {
int16_t offsetX = 0;
int16_t lastOffsetX;
bool tampil=true;
uint8_t lastKar = strlen(teks);
uint16_t repI = 0;
while (tampil){
const char *ptr = teks;
lastOffsetX = offsetX;
int16_t currentOffsetX;
mx.clear();
for (int karI = 0; karI < lastKar; karI++) {
uint8_t size;
const LED *pola = getHuruf(ptr[karI], size);
currentOffsetX = lastOffsetX;
if (pola) {
int16_t posisiKol;
for (uint8_t i = 0; i < size; i++) {
int16_t x = pola[i].x;
int16_t y = pola[i].y;
int16_t posisiKol = lastOffsetX + x;
currentOffsetX = posisiKol;
if (posisiKol >= 0 && posisiKol < maxX) {
if (y < 8)
mx.setPoint(y, posisiKol, true);
else
mx.setPoint(y - 8, posisiKol + maxX, true);
if (i == (size - 1) && karI == (lastKar - 1)) {
tampil=false;
delay(3000);
}
}
}
}
lastOffsetX = currentOffsetX-2;
}
offsetX++;
repI++;
mx.update();
delay(100);
}
}
void setup() {
Serial.begin(9600);
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
mx.clear();
}
void loop() {
tampilkanTeks(mx, "ABD");
delay(50);
}