ARDUINO PROGRAM
/* JUDUL : PROGRAM JAM DIGITAL P10 1 PANEL DENGAN NANO & RTC 3231
* COPY RIGHT : BELAJAR TEHNOLOGI JAMAN NOW
* PUBLISH : 13 FEB 2022
* EMAIL : aplikasihebatstudio@gmail.com
*
* NANO - P10
* ----------
* PIN YANG DISAMBUNG
* Arduino P-10
* D6 -> A
* D7 -> B
* D8 -> SCLK
* D9 -> OE (ENABLE)
* D11 -> DATA
* D13 -> CLK
* GND -> GND
RTC 3231
--------
* GND >> Pin GND
* VCC >> Pin 5V
* SDA >> Pin SDA (A4)
* SCL >> Pin SCL (A5)
* SQW >> tidak dihubungkan
* 32K >> tidak dihubungkan
*/
#include <Wire.h>
#include "RTClib.h"
#include "DMD.h"
#include "TimerOne.h"
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
/***** P10 DISPLAY SETTING ***********************************/
DMD dmd( DISPLAYS_ACROSS , DISPLAYS_DOWN);
RTC_DS3231 rtc;
// int tahun;
byte jam;
byte menit; //|
byte detik;
byte bulan;
byte tahun;
byte hari;
byte tgl;
int k; int j;
void drawText(int kolom,int baris,String text);
char weekDay[][7] = {"Mingg" ,"Senin","Slasa","Rabu", "Kamis", "jumat", "Sabtu"}; // array hari, dihitung mulai dari senin, hari senin angka nya =0,
//byte detik1=0;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup()
{
Timer1.initialize( 4000 ); // I find the default 5000 gives a visible flicker
Timer1.attachInterrupt( ScanDMD );
dmd.selectFont(SystemFont5x7);
dmd.clearScreen( true );
Wire.begin();
rtc.begin();
// just datatime
// rtc.adjust(DateTime(2022, 02, 13, 14, 50, 0));
k=0;
j=0;
}
void loop()
{
tampil_jam_kecil_tgl(30);
}
void drawText(int kolom,int baris,String text)
{
int pj_text=text.length()+1;
char text_char[pj_text];
text.toCharArray(text_char,pj_text);
dmd.drawString(kolom,baris,text_char,pj_text,GRAPHICS_NORMAL);
}
void tampil_jam_kecil_tgl(int lama)
{
// dmd.clearScreen(true);
//lama=60;
String hh,mm,ss;
for(int i=0;i<lama;i++)
{
DateTime now = rtc.now();
jam= now.hour();
menit=now.minute();
detik=now.second();
tahun = now.year();
bulan = now.month();
tgl = now.day();
hh=Konversi(jam);
mm=Konversi(menit);
ss=Konversi(detik);
dmd.selectFont(SystemFont5x7);
if(k%2==0)
{
drawText(1,0,hh+":"+mm);
//drawText(1,9,Konversi(tgl)+"/"+Konversi(bulan));
k++;
}
else {
drawText(1,0,hh+" "+mm);
k=0;
}
j++;
if(j==1)
{
drawText(1,9,Konversi(tgl)+"/"+Konversi(bulan));
}
if(j==10)
{
drawText(1,9,String(weekDay[hari]));
}
if (j>=20) j=0;
delay(1000);
}
}
///Konversi angka agar ada nol didepannya jika diawah 10
String Konversi(int sInput) {
if (sInput < 10)
{
return"0" + String(sInput);
}
else
{
return String(sInput);
}
}
No comments:
Post a Comment