#include "Arduino.h"
#include <LedControl.h>
int buttonPin = 2;
int DIN = 0;
int CS = 1;
int CLK = 3;
int numb=1;
int pres=0;
int SPEED_1 = 40;
int SPEED_2 = 100;
int SPEED_3 = 500;
LedControl lc=LedControl(DIN,CLK,CS,4);
byte I[8]= {0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x7e};
byte Heart_1[8]= {0x6C,0xFE,0xFE,0xFE,0x7C,0x38,0x10,0x00};
byte Heart_2[8]= {0x00,0x36,0x7F,0x7F,0x7F,0x3E,0x1C,0x08};
byte U1[8]= {0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0xFF,0x7E};
byte Trans_1[8]= {0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55};
byte Trans_2[8]= {0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
byte Blank[8]= {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
byte C[8] = {0x78,0x7c,0xe,0x6,0x6,0xe,0x7c,0x78};
byte A[8] = {0x18,0x3c,0x66,0x66,0x7e,0x7e,0x66,0x66};
byte loveL[8] = {0x0C,0x1E,0x3F,0x7F,0x7F,0x3F,0x1F,0x0F};
byte loveR[8] = {0x30,0x78,0xFC,0xFE,0xFE,0xFC,0xF8,0xF0};
// Define characters for "kamu mau ga jadi pacar aku"
byte K[8] = {0x7C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x7C, 0x00};
byte M[8] = {0x66, 0x7E, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x00};
byte U2[8] = {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x00};
byte G[8] = {0x3C, 0x66, 0x66, 0x60, 0x6E, 0x66, 0x3C, 0x00};
byte J[8] = {0x3C, 0x18, 0x18, 0x18, 0x18, 0x5A, 0x3C, 0x00};
byte D[8] = {0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x00};
byte P[8] = {0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00};
byte R[8] = {0x7C, 0x66, 0x66, 0x7C, 0x70, 0x6C, 0x66, 0x00};
byte Space[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // space
byte* message[] = {K, A, M, U2, Space, M, A, U2, Space, G, A, Space, J, A, D, I, Space, P, A, C, A, R, Space, A, K, U2};
void setup(){
lc.shutdown(0,false);
lc.shutdown(1,false);
lc.shutdown(2,false);
lc.shutdown(3,false);
lc.setIntensity(0,15);
lc.setIntensity(1,15);
lc.setIntensity(2,15);
lc.setIntensity(3,15);
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop(){
ButtonScan();
switch (numb) {
case 1:
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
lc.setIntensity(0,0);
lc.setIntensity(1,0);
lc.setIntensity(2,0);
lc.setIntensity(3,0);
delay(SPEED_1);
break;
case 2:
for (int i=0;i<=2;i++){
printByte(2,I);
HeartBeat();
HeartBeat();
HeartBeat();
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
printByte(3,C);
printByte(2,A);
printByte(1,C);
printByte(0,A);
delay(3000);
}
numb = 3;
break;
case 3:
scrollMessage(message, sizeof(message)/sizeof(message[0]), SPEED_2);
numb = 1;
break;
}
}
void printByte(int matrix, byte character []){
for(int i=0; i<8; i++){
lc.setRow(matrix, i, character[i]);
}
}
void HeartBeat (){
printByte(3,Trans_1);
lc.setIntensity(0,15);
lc.setIntensity(1,15);
lc.setIntensity(2,15);
lc.setIntensity(3,15);
printByte(0,Trans_1);
printByte(1,Heart_2);
lc.setIntensity(0,1);
lc.setIntensity(1,1);
lc.setIntensity(2,1);
lc.setIntensity(3,1);
delay(40);
printByte(3,Trans_2);
printByte(0,Trans_2);
printByte(1,Heart_1);
delay(40);
printByte(3,Trans_1);
printByte(0,Trans_1);
printByte(1,Heart_2);
delay(40);
printByte(3,Trans_1);
printByte(0,Trans_1);
printByte(1,Heart_1);
delay(40);
printByte(3,Trans_2);
printByte(0,Trans_2);
printByte(1,Heart_2);
delay(40);
}
void ButtonScan(){
if(digitalRead(buttonPin)==0){
if(pres==0){
numb++;
pres=1;
}
} else {
pres=0;
}
if(numb == 4){
numb = 1;
}
}
void scrollMessage(byte* message[], int length, int delayTime) {
int totalCols = length * 8 + 32; // Total number of columns to scroll through, including space between characters and extra space for scrolling effect
for (int col = 0; col < totalCols; col++) {
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
for (int matrix = 0; matrix < 4; matrix++) {
for (int row = 0; row < 8; row++) {
byte displayRow = 0;
for (int bit = 0; bit < 8; bit++) {
int messageCol = col - (matrix * 8 + (7 - bit));
if (messageCol >= 0 && messageCol < length * 8) {
int charIndex = messageCol / 8;
int charCol = messageCol % 8;
if (charIndex < length) {
displayRow |= ((message[charIndex][row] >> (7 - charCol)) & 0x01) << bit;
}
}
}
lc.setRow(matrix, row, displayRow);
}
}
delay(delayTime);
}
}