0% found this document useful (0 votes)
160 views5 pages

Jam Alarm

This document contains the code for an Arduino project that displays the time on a DMD display panel and includes an alarm function. It initializes an RTC module to get the date and time. In the main loop, it retrieves the current date and time from the RTC, formats it, and displays it on the panel. It also includes a subroutine to scroll the full date across the display. The alarm function allows setting an alarm based on hour, minute, duration, and delay for the buzzer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views5 pages

Jam Alarm

This document contains the code for an Arduino project that displays the time on a DMD display panel and includes an alarm function. It initializes an RTC module to get the date and time. In the main loop, it retrieves the current date and time from the RTC, formats it, and displays it on the panel. It also includes a subroutine to scroll the full date across the display. The alarm function allows setting an alarm based on hour, minute, duration, and delay for the buzzer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

/**********************¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

¤¤¤¤¤¤¤¤**********************
jam alarm

Muhammad ilham
https://www.youtube.com/channel/UC7xxReA2RnJUVhiMfhUO83w

TEST arduino IDE v1.8.13*/

#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "Arial_black_16.h"
#include "Font_6x14.h"
//---------------------------------------------------------------------------------
-----Configuration P10
#define DISPLAYS_ACROSS 1 //-> Number of P10 panels used, side to side.
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
//---------------------------------------------------------------------------------
-----

RTC_DS1307 rtc; //-> RTC Declaration


int relay = 5;

//---------------------------------------------------------------------------------
-----Variables for time and date
int _day, _month, _year, _hour24, _hour12, _minute, _second, _dtw;
int hr24;
String st;
char nameoftheday[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"};
char month_name[12][12] = {"January","February", "March", "April", "May", "June",
"Jult", "August", "September", "October", "November", "December"};
int Buzzer = 5;
//---------------------------------------------------------------------------------
-----
//---------------------------------------------------------------------------------
-----Variable for Millis
const long interval = 1000; //-> Retrieve time and date data every 1 second
unsigned long previousMillis = 0;
//---------------------------------------------------------------------------------
-----
//---------------------------------------------------------------------------------
-----Variable to display hours and minutes
char hr_24 [3];
String str_hr_24;
char mn [3];
String str_mn;
//---------------------------------------------------------------------------------
-----
//---------------------------------------------------------------------------------
-----ScanDMD()
void ScanDMD() {
dmd.scanDisplayBySPI();
}
//---------------------------------------------------------------------------------
-----setup
void setup() {
Serial.begin(115200);
Wire.begin();

rtc.begin();
if (! rtc.isrunning() )
{
Serial.println("RTC is Not Running");
}
pinMode(relay, OUTPUT);
Serial.println("Arduino RTC DS1307");
delay(1000);
pinMode(Buzzer,OUTPUT);

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
Timer1.initialize(1000);
Timer1.attachInterrupt(ScanDMD);
dmd.clearScreen(true);
}
//---------------------------------------------------------------------------------
-----

//---------------------------------------------------------------------------------
-----loop
void loop() {
//set alaram (jam,menit,delay bunyi alaram dihitung dari menit jam,delay alaram
aktif
alaram(14,34,10,3000);
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.println();

Serial.println();
delay(1000);
//_____________________________________________________millis() to display time
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; //-> save the last time
GetDateTime(); //-> Retrieve time and date data from DS1307

dmd.selectFont(Font_6x14);

//=====================================================Showing hour in P10


str_hr_24=String(_hour24);
str_hr_24.toCharArray(hr_24,3);

if (_hour24<10) {
dmd.drawString(0, 0, "0", 1, GRAPHICS_NORMAL);
dmd.drawString(7, 0, hr_24, 1, GRAPHICS_NORMAL);
}
else {
dmd.drawString(0, 0, hr_24, 2, GRAPHICS_NORMAL);
}
//=====================================================

//=====================================================Showing ":" in P10


if (_second %2 == 0) {
dmd.drawFilledBox(15,3,16,4, GRAPHICS_OR);
dmd.drawFilledBox(15,11,16,12, GRAPHICS_OR);
}
else {
dmd.drawFilledBox(15,3,16,4, GRAPHICS_NOR);
dmd.drawFilledBox(15,11,16,12, GRAPHICS_NOR);
}
//=====================================================

//=====================================================Showing minutes in P10


str_mn=String(_minute);
str_mn.toCharArray(mn,3);

if (_minute<10) {
dmd.drawString(19, 0, "0", 1, GRAPHICS_NORMAL);
dmd.drawString(26, 0, mn, 1, GRAPHICS_NORMAL);
}
else {
dmd.drawString(19, 0, mn, 2, GRAPHICS_NORMAL);
}
//=====================================================

//=====================================================Call the
scrolling_date() subroutine to display the date.
if (_second==11) { //-> Display the date when seconds equal to 11
scrolling_date();
}
//=====================================================
}
//_____________________________________________________
}
//---------------------------------------------------------------------------------
-----

//------------------------------------------------------------------------
Subroutine to retrieve or update the time and date from DS1307
void GetDateTime() {
DateTime now = rtc.now();
_day=now.day();
_month=now.month();
_year=now.year();
_hour24=now.hour();
_minute=now.minute();
_second=now.second();
_dtw=now.dayOfTheWeek();

hr24=_hour24;
if (hr24>12) {
_hour12=hr24-12;
}
else if (hr24==0) {
_hour12=12;
}
else {
_hour12=hr24;
}

if (hr24<12) {
st="AM";
}
else {
st="PM";
}
}
//------------------------------------------------------------------------

//------------------------------------------------------------------------
Subroutine to display days, months and years
void scrolling_date() {
String Date = String(nameoftheday[_dtw]) + ", " + String(_day) + "-" +
String(month_name[_month-1]) + "-" + String(_year);
char dt[50];
Date.toCharArray(dt,50);

dmd.clearScreen(true);
dmd.selectFont(Arial_Black_16);
dmd.drawMarquee(dt,strlen(dt),(32*DISPLAYS_ACROSS)-1,0);
boolean ret=false;
while(!ret){
ret=dmd.stepMarquee(-1,0);
delay(75); //-> //-> delay For scroll speed
}
dmd.clearScreen(true);
return;
}
void alaram(int jamke,int menitke,int lama,int delaybunyi){
DateTime now = rtc.now();
if (now.hour() == jamke) // APEL
if (now.minute() == menitke)
if (now.second() <= lama)
{
digitalWrite(relay, HIGH);
Serial.println("ON");
delay(delaybunyi);

}
else
{
digitalWrite(relay, LOW);
}
}
//------------------------------------------------------------------------

You might also like