VIDEO
Program:
/*---------------------------- ------------------------------ ------------
* Project : Jam Digital DotMatrix Display Detik Geser
* Author : Amar Lakar Cengkal
* Version : 1.0
*
----------------------------- ------------------------------ -----------*/
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/MyBigFont.h>
#include <fonts/Arial_Black_16.h>
#include <stdio.h>
#include <DS1302.h>
#define Panjang 1
#define Lebar 1
#define max_char 50
SoftDMD dmd(Panjang, Lebar);
char message[max_char];
char tahun[5];
char bulan[7];
char tanggal[7];
char jam[7];
char menit[7];
char detik[7];
char hari[7];
char tulisan[20];
char r_char;
byte asu= 0;
int i,r;
int a=0;
int taek=0;
namespace {
const int kCePin = A2; // Chip Enable
const int kIoPin = A1; // Input/Output
const int kSclkPin = A0; // Serial Clock
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Minggu";
case Time::kMonday: return "Senin";
case Time::kTuesday: return "Selasa";
case Time::kWednesday: return "Rabu";
case Time::kThursday: return "Kamis";
case Time::kFriday: return "Jumat";
case Time::kSaturday: return "Sabtu";
}
return "(unknown day)";
}
////////////////////////////// ////////////////////////////// /////////
void setjam()
{
if(Serial3.available())
{
for(i=0; i<50; i++)
{
message[i] = '\0';
}
for(i=0; i<7; i++)
{
tahun[i] = '\0';
bulan[i] = '\0';
tanggal[i] = '\0';
jam[i] = '\0';
menit[i] = '\0';
detik[i] = '\0';
hari[i] = '\0';
}
for(i=0; i<20; i++)
{
tulisan[i] = '\0';
}
taek=0;
}
while(Serial3.available() > 0)
{
if(taek < (max_char-1))
{
r_char = Serial3.read();
message[taek] = r_char;
taek++;
message[taek] = '\0';
}
r=1;
}
if(r==1)
{
if(message[0]=='%')
{
for(int i=0; i<20; i++)
{
if(message[i+1]=='&')
{
goto bawah;
}
tulisan[i]=message[i+1];
}
}
for(int i=0; i<24; i++)
{
if(message[i]=='#')
{
for(int j=0; j<24; j++)
{
i++;
if(message[i]=='#')
{
for(int k=0; k<24; k++)
{
i++;
if(message[i]=='#')
{
for(int l=0; l<24; l++)
{
i++;
if(message[i]=='#')
{
for(int m=0; m<24; m++)
{
i++;
if(message[i]=='#')
{
for(int n=0; n<24; n++)
{
i++;
if(message[i]=='#')
{
for(int o=0; o<24; o++)
{
i++;
if(message[i]=='&')
{
goto bawah;
}
hari[o] = message[i];
}
}
detik[n] = message[i];
}
}
menit[m] = message[i];
}
}
jam[l] = message[i];
}
}
tanggal[k] = message[i];
}
}
bulan[j] = message[i];
}
}
tahun[i] = message[i];
}
bawah:
r=2;
}
if(r==2)
{
if(atoi(hari)==1)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kMonday);
rtc.time(t);
}
else if(atoi(hari)==2)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kTuesday);
rtc.time(t);
}
else if(atoi(hari)==3)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kWednesday);
rtc.time(t);
}
else if(atoi(hari)==4)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kThursday);
rtc.time(t);
}
else if(atoi(hari)==5)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kFriday);
rtc.time(t);
}
else if(atoi(hari)==6)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kSaturday);
rtc.time(t);
}
else if(atoi(hari)==7)
{
Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kSunday);
rtc.time(t);
}
//Time t(2017, 1, 26, 21, 10, 50, Time::kSunday);
//Time t(atoi(tahun), atoi(bulan), atoi(hari), atoi(jam), atoi(menit), atoi(detik), Time::kSunday);
//rtc.time(t);
r=0;
}
}
////////////////////////////// ////////////////////////////// /////////
void printTime() {
dmd.clearScreen();
dmd.selectFont(SystemFont5x7);
int g=0,h=0;;
for(int i=-65;i<=50;i++)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
// snprintf(bufd, sizeof(bufd), "%02d",
// t.sec);
snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( i, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int i=50;i>=-65;i--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
// snprintf(bufd, sizeof(bufd), "%02d",
// t.sec);
snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( i, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int j=-65;j<=50;j++)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
snprintf(bufd, sizeof(bufd), "%s",
day.c_str());
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( j, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int j=50;j>=-65;j--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
snprintf(bufd, sizeof(bufd), "%s",
day.c_str());
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( j, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int j=-65;j<=50;j++)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
snprintf(bufd, sizeof(bufd), "%02d%s",
t.sec, "sec.");
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( j, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int j=50;j>=-65;j--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
snprintf(bufd, sizeof(bufd), "%02d%s",
t.sec, "sec.");
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( j, 9, bufd );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int k=32;k>=-55;k--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
//snprintf(bufd, sizeof(bufd), "%02d%s",
// t.sec, "sec.");
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( k, 9, "KURNIAWAN" );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int k=32;k>=-40;k--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
//snprintf(bufd, sizeof(bufd), "%02d%s",
// t.sec, "sec.");
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( k, 9, "INDRA" );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
setjam();
for(int k=32;k>=-40;k--)
{
// 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 bufd[50];
snprintf(buf, sizeof(buf), "%02d:%02d",
//snprintf(bufd, sizeof(bufd), "%02d%s",
// t.sec, "sec.");
//snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);
dmd.clearScreen();
//delay(5);
dmd.drawString( g, 0, buf ); //x,y
dmd.drawString( k, 9, "AMAR" );
delay(100);
if(h==0)
{
if(g==2) h=1;
g++;
}
else if(h==1)
{
if(g==1) h=0;
g--;
}
}
}
} // namespace ////////////////////////////// ////////////////////////
void setup() ////////////////////////////// ////////////////////////////// //////////
{
// Setup DMD
dmd.setBrightness(255);
dmd.clearScreen();
dmd.selectFont(SystemFont5x7);
dmd.begin();
rtc.writeProtect(false);
rtc.halt(false);
Serial3.begin(9600);
tulisan[0]='x';
}
void loop() ////////////////////////////// ////////////////////////////
{
printTime();
dmd.clearScreen();
dmd.selectFont(MyBigFont);
if(a==0)
{
setjam();
for(int k=33;k>=-120;k--)
{
dmd.clearScreen();
dmd.drawString( k, 0, "RI");
delay(55);
}
setjam();
if(tulisan[0]!='x')
{
dmd.clearScreen();
dmd.selectFont(Arial_Black_16) ;
for(int k=33;k>=-240;k--)
{
dmd.clearScreen();
dmd.drawString( k, 0, tulisan);
delay(55);
}
}
a=1;
}
else if(a==1)
{
setjam();
for(int k=33;k>=-120;k--)
{
dmd.clearScreen();
dmd.drawString( k, 0, "KAM");
delay(55);
}
setjam();
if(tulisan[0]!='x')
{
dmd.clearScreen();
dmd.selectFont(Arial_Black_16) ;
for(int k=33;k>=-240;k--)
{
dmd.clearScreen();
dmd.drawString( k, 0, tulisan);
delay(55);
}
}
a=0;
}
}