#include <LedControl.h>
// Pin koneksi dari MAX7219 ke Arduino
#define DIN 12 // Pin Data In
#define CLK 10 // Pin Clock
#define CS 11 // Pin Chip Select
LedControl lc = LedControl(DIN, CLK, CS, 4); // 4 device MAX7219 connected
// Gambar icon yang akan berjalan (simbol hati sebagai contoh) pada 32 kolom
byte heart[4][8] = {
{0b00000000, 0b01100110, 0b10011001, 0b10000001, 0b10000001, 0b01000010, 0b00100100, 0b00011000}, // Bagian 1
{0b00000000, 0b01100110, 0b10011001, 0b10000001, 0b10000001, 0b01000010, 0b00100100, 0b00011000}, // Bagian 2
{0b00000000, 0b01100110, 0b10011001, 0b10000001, 0b10000001, 0b01000010, 0b00100100, 0b00011000}, // Bagian 3
{0b00000000, 0b01100110, 0b10011001, 0b10000001, 0b10000001, 0b01000010, 0b00100100, 0b00011000}, // Bagian 4
};
// Fungsi untuk menampilkan gambar pada dot matrix
void displayIcon(byte icon[4][8]) {
for (int device = 0; device < 4; device++) {
for (int row = 0; row < 8; row++) {
lc.setRow(device, row, icon[device][row]); // Menampilkan tiap bagian pada modul 8x8
}
}
}
// Fungsi untuk menggeser gambar ke kiri
void shiftLeft(byte icon[4][8]) {
for (int row = 0; row < 8; row++) {
// Geser semua kolom pada modul 1, 2, 3, dan 4
byte temp = icon[0][row] & 0b10000000; // Simpan bit paling kiri dari modul pertama
for (int device = 0; device < 4; device++) {
byte nextTemp = icon[device][row] & 0b10000000; // Simpan bit paling kiri dari modul berikutnya
icon[device][row] = (icon[device][row] << 1) | (device < 3 ? (icon[device + 1][row] >> 7) : 0); // Geser ke kiri
if (device == 3) {
icon[device][row] |= (temp >> 7); // Tambahkan bit paling kiri ke modul terakhir
}
}
}
}
void setup() {
for (int i = 0; i < 4; i++) {
lc.shutdown(i, false); // Aktifkan modul MAX7219
lc.setIntensity(i, 8); // Atur kecerahan (0-15)
lc.clearDisplay(i); // Bersihkan tampilan awal
}
}
void loop() {
while (true) { // Looping tanpa henti
for (int i = 0; i < 32; i++) { // 32 kolom total
displayIcon(heart); // Tampilkan gambar di LED Matrix
delay(50); // Tunggu sejenak untuk pergerakan yang lebih halus
shiftLeft(heart); // Geser gambar ke kiri
}
}
}