#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <FastLED.h>
#include <ArduinoTrace.h>
#include "Bitmaps.h"
#include "Font.h"
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 6
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
#define BUTTON_1_PIN 3 // Ubah ini sesuai dengan pin tempat push button pertama Anda terhubung
#define BUTTON_2_PIN 4 // Ubah ini sesuai dengan pin tempat push button kedua Anda terhubung
#define BUTTON_3_PIN 5 // Ubah ini sesuai dengan pin tempat push button ketiga Anda terhubung
#define SWITCH_PIN 8 // Tambahkan ini untuk pin sakelar geser
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
CRGB leds[MAX_DEVICES * 8]; // Anggap 8 LED per perangkat, sesuaikan jika diperlukan
typedef struct
{
textEffect_t effect;
char * psz;
uint16_t speed;
uint16_t pause;
} sCatalog;
sCatalog catalog[] =
{
{ PA_DISSOLVE, "@ @", 15, 5 },
{ PA_OPENING_CURSOR, "♡", 15, 5 },
{ PA_BLINDS, "$$$", 10, 3 },
{ PA_SCROLL_RIGHT, ":) :) :) :) :)", 3, 1 },
{ PA_CLOSING_CURSOR, "~ByE~", 15, 5 },
{ PA_SCROLL_RIGHT, "Sekian Terima Kasih", 3, 5 },
};
uint16_t SnowSpeed;
uint16_t AnimationSpeed;
uint16_t BellAnimationSpeed;
bool isGreen = false; // Variabel untuk melacak warna LED
void setup()
{
Serial.begin(57600);
AnimationSpeed = 200;
BellAnimationSpeed = 200;
SnowSpeed = 100;
for (uint8_t i = 0; i < ARRAY_SIZE(catalog); i++)
{
catalog[i].speed *= 10;
catalog[i].pause *= 500;
}
P.begin();
P.setFont(myFont);
P.setInvert(false);
// Inisialisasi FastLED
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, sizeof(leds));
}
void loop()
{
bool switchState = digitalRead(SWITCH_PIN);
bool button1State = digitalRead(BUTTON_1_PIN);
bool button2State = digitalRead(BUTTON_2_PIN);
bool button3State = digitalRead(BUTTON_3_PIN);
// Logika untuk push button 1
if (button1State == HIGH) {
catalog[5].effect = PA_SCROLL_LEFT; // Ubah indeks animasi sesuai kebutuhan
} else {
catalog[5].effect = PA_SCROLL_RIGHT; // Ubah indeks animasi sesuai kebutuhan
}
// Logika untuk push button 2
if (button2State == HIGH) {
catalog[5].effect = PA_SCROLL_DOWN; // Ubah indeks animasi sesuai kebutuhan
}
// Logika untuk push button 3
if (button3State == HIGH) {
catalog[5].effect = PA_SCROLL_UP; // Ubah indeks animasi sesuai kebutuhan
}
for (uint8_t i = 0; i < ARRAY_SIZE(catalog); i++) {
if (switchState && i == 5) {
// Tampilkan teks tertentu ketika sakelar berada dalam posisi TRUE
P.displayText(catalog[i].psz, PA_CENTER, catalog[i].speed, catalog[i].pause, catalog[i].effect, catalog[i].effect);
while (!P.displayAnimate());
} else if (SpecialAnimations(catalog[i].psz) == false) {
// Tampilkan animasi lain
P.displayText(catalog[i].psz, PA_CENTER, catalog[i].speed, catalog[i].pause, catalog[i].effect, catalog[i].effect);
while (!P.displayAnimate());
}
delay(catalog[i].pause);
}
// Perbarui tampilan FastLED
FastLED.show();
}
bool SpecialAnimations(char *Code)
{
if((strcmp(Code, "BELL") == 0) || (strcmp(Code, "SNOW") == 0) || (strcmp(Code, "STARS") == 0))
{
if(strcmp(Code, "BELL") == 0)
AnimateBell();
else if(strcmp(Code, "SNOW") == 0)
Snow();
else if(strcmp(Code, "STARS") == 0)
FlashingStars();
return true;
}
else
return false;
}
void AnimateBell()
{
for(int i=0; i<1; i++)
{
P.displayText("||||6", PA_LEFT, 0, AnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("|||7", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||8", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||9", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||0", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||9", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||8", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("|||7", PA_LEFT, 0, BellAnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
}
}
void FlashingStars()
{
for(int i=0; i<8; i++)
{
P.displayText("* + *", PA_CENTER, 0, AnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("+ * +", PA_CENTER, 0, AnimationSpeed, PA_PRINT, PA_NO_EFFECT);
while (!P.displayAnimate());
}
}
void Snow()
{
P.displayText("* * *", PA_CENTER, SnowSpeed, 0, PA_SCROLL_DOWN, PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText(" * *", PA_CENTER, SnowSpeed, 0, PA_SCROLL_DOWN, PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText("* * * *", PA_CENTER, SnowSpeed, 0, PA_SCROLL_DOWN, PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText("* * *", PA_CENTER, SnowSpeed, 0, PA_SCROLL_DOWN, PA_SCROLL_DOWN);
while (!P.displayAnimate());
}