#include <stdio.h>
#include <Ds1302.h>
#include <SPI.h>
#include <DMD2.h>
#include <TimerOne.h>
#include "Arial14.h"
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 1 //-> Number of P10 panels used, side to side.
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
char *Text = "";
char *Text1 = "";
boolean ret=false;
namespace {
const int kCePin = 2; // Chip Enable
const int kIoPin = 3; // Input/Output
const int kSclkPin = 4; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Min";
case Time::kMonday: return "Sen";
case Time::kTuesday: return "Sel";
case Time::kWednesday: return "Rab";
case Time::kThursday: return "Kam";
case Time::kFriday: return "Jum";
case Time::kSaturday: return "Sab";
}
return "(unknown day)";
}
void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
char buf1[50];
snprintf(buf1, sizeof(buf1),"%s",day.c_str());
snprintf(buf, sizeof(buf), "%02d:%02d", t.hr, t.min);
dmd.selectFont(SystemFont5x7);
dmd.drawString(1,0, buf, 5, GRAPHICS_NORMAL);
dmd.drawString(8,8, buf1, 3, GRAPHICS_NORMAL);
// Print the formatted string to serial so we can see the time.
Serial.println(buf);
}
}
void ScanDMD() {
dmd.scanDisplayBySPI();
}
void setup(void) {
Timer1.initialize(1000);
Timer1.attachInterrupt(ScanDMD);
dmd.clearScreen(true);
Serial.begin(9600);
rtc.writeProtect(false);
rtc.halt(false);
Time t(2023, 9, 20, 18, 21, 50, Time::kWednesday);
// Set the time and date on the chip.
rtc.time(t);
}
void loop() {
printTime();
delay(20000);
dmd.selectFont(Arial_14);
Text = "Selamat Datang di Ctech Store";
dmd.drawMarquee(Text,strlen(Text),(32*DISPLAYS_ACROSS)-1,2);
while(!ret){
ret=dmd.stepMarquee(-1,0);
delay(100);
}
ret=false;
delay (1000);
Text1 = "Selamat Berbelanja";
dmd.drawMarquee(Text1,strlen(Text1),(32*DISPLAYS_ACROSS)-1,2);
while(!ret){
ret=dmd.stepMarquee(-1,0);
delay(100);
}
ret=false;
}