Header Ads Widget

HOW TO MAKE A DIGITAL CLOCK USING ARDUINO

HOW  TO MAKE A DIGITAL CLOCK USING ARDUINO :

An Arduino digital clock can be built in many ways. The most common way is to use an Arduino Uno and a 16x2 LCD screen. Here I am using the Max7219 led matrix.
First, the Max7219 led matrix is connected to the Arduino using wires. Next, the Arduino code is written and uploaded to the Arduino. Finally, the clock is set, and it displayed the time on the theMax7219 led matrix.

How this project works :

 video:
what is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects.
Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do this you use the Arduino programming language (based on Wiring) and the Arduino Software (IDE), based on Processing.
There are many versions of Arduino boards available, each with its own set of capabilities. The best way to select the right board for your project is to consider what inputs and outputs you'll need and what amount of processing power you'll need.

what is a led matrix display?

A Max7219 led matrix is a type of led display that is commonly used in electronic projects. It is made up of a series of LEDs that are arranged in a specific pattern. The LEDs are controlled by a chip that determines what pattern the LEDs should be displayed in. The Max7219 is a popular choice for projects because it is relatively easy to use and is very versatile.

MAX7219 led matrix display is a great way to add some bling to your project. You can use it to display messages, create animations, or just add some visual interest. The best part is that it's easy to use and relatively inexpensive. You can purchase a pre-assembled module, or you can DIY it with a few components.

If you're looking for a way to add some visual interest to your project, then a MAX7219 led matrix display is a great option. You can use it to display messages, create animations, or just add some visual interest. The best part is that it's easy to use and relatively inexpensive. You can purchase a pre-assembled module, or you can DIY it with a few components.


CIRCUIT :




what is DS1307?

The DS1307 is a simple, low-power I2C real-time clock (RTC) with an integrated battery backup. It is a low-cost, yet accurate RTC chip that is used in a wide variety of electronic devices. The DS1307 can be controlled via I2C and has a built-in oscillator that can keep track of time with accuracy. The device can maintain time in backup mode when the power is off.
CODE : 
#include <MD_Parola.h>
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 RTC;
//DateTime now;
 
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10
 
int i = 9;
int Animation;
String RandAn;
 
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
 
char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
char monthOfTheYear[12][12] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
 
struct sCatalog
{
  textEffect_t  effect;   
  const char *  psz;      
  uint16_t      speed;    
  uint16_t      pause;    
};
 
sCatalog catalog[] =
{
  { PA_PRINT,"",80,3000 },
  { PA_SCROLL_UP,"",80,3000 },
  { PA_SCROLL_DOWN,"",80,3000 },
  { PA_SCROLL_LEFT,"",80,3000 },
  { PA_SCROLL_RIGHT,"",80,3000 },
  { PA_SPRITE,"",80,3000  },
  { PA_SLICE,"",15,3000  },
  { PA_MESH,"",150,3000  },
  { PA_FADE,"",250,3000  },
  { PA_DISSOLVE,"",500,3000  },
  { PA_BLINDS,"",120,3000  },
  { PA_RANDOM,"",50,3000  },
  { PA_WIPE,"",80,3000  },
  { PA_WIPE_CURSOR,"",80,3000  },
  { PA_SCAN_HORIZ,"",80,3000  },
  { PA_SCAN_HORIZX,"",80,3000  },
  { PA_SCAN_VERT,"",80,3000  },
  { PA_SCAN_VERTX,"",80,3000  },
  { PA_OPENING,"",80,3000  },
  { PA_OPENING_CURSOR,"",80,3000  },
  { PA_CLOSING,"",80,3000  },
  { PA_CLOSING_CURSOR,"",80,3000  },
  { PA_SCROLL_UP_LEFT,"",80,3000  },
  { PA_SCROLL_UP_RIGHT,"",80,3000   },
  { PA_SCROLL_DOWN_LEFT,"",80,3000  },
  { PA_SCROLL_DOWN_RIGHT,"",80,3000  },
  { PA_GROW_UP,"",80,3000  },
  { PA_GROW_DOWN,"",80,3000  },
};
 
 
// Sprite Definitions
const uint8_t F_PMAN1 = 6;
const uint8_t W_PMAN1 = 8;
static const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] =  // gobbling pacman animation
{
  0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
  0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
};
 
const uint8_t F_PMAN2 = 6;
const uint8_t W_PMAN2 = 18;
static const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] =  // ghost pursued by a pacman
{
  0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
};
 
 
void setup()
{
  //Serial.begin(9600);
  P.begin();
  P.setInvert(false); 
  P.setIntensity(0);
  Wire.begin();
  RTC.begin();
 if (! RTC.isrunning())
  {
        //Serial.println("RTC is NOT running!");
        RTC.adjust(DateTime(__DATE__, __TIME__));
    }
#if ENA_SPRITE
  P.setSpriteData(pacman1, W_PMAN1, F_PMAN1, pacman2, W_PMAN2, F_PMAN2);
#endif
        P.displayText("Digital clock By MEWORKS" , PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); 
         while (!P.displayAnimate());
}
 
const char *ZiuaCurenta = " ";
 
String Hour;
String TIMP=" ";
String ORA=" ";
String MINUT=" ";
String SECUNDA=" ";
String DATA="";
 
String Day;
String Month;
String Year; 
void loop()
{
 DateTime now=RTC.now();
  String DayOfWeek = daysOfTheWeek[now.dayOfTheWeek()];
  String MonthOfYear = monthOfTheYear[now.month() - 1];
  const char *DayOfWeekC = DayOfWeek.c_str();
  const char *MonthOfYearC = MonthOfYear.c_str();
 
  ORA = (now.hour());
  if (ORA.length() < 2)
         {
           ORA = "0"+ ORA;
         }
 
  MINUT = (now.minute());
  if (MINUT.length() < 2)
         {
           MINUT = "0"+ MINUT;
         }
 
  TIMP = ORA + ":" + MINUT;
 
  const char *Timp = TIMP.c_str();
 
  Day = now.day();
  Month = now.month();
  Year = now.year();
 
  const char *Ziua = Day.c_str();
  const char *Luna = Month.c_str();
  const char *Anul = Year.c_str();
 
  String Date = Day + "/" + Month + "/" + Year;
  const char *Data = Date.c_str(); 
 
  
   if (i == 1)
    {
        Animation = random(1, 29);
        P.displayText(DayOfWeekC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect); 
         while (!P.displayAnimate());
    }
  if (i == 2)
    {
        Animation = random(1, 29);
        P.displayText(Ziua, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect); 
         while (!P.displayAnimate());
    }
    if (i == 3)
    {
        Animation = random(1, 29);
        P.displayText(MonthOfYearC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect); 
         while (!P.displayAnimate());
    }
    if (i == 4)
    {
        Animation = random(1, 29);
        P.displayText(Anul, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect); 
         while (!P.displayAnimate());
    }
 
    if (i == 5)
    {
        Animation = random(1, 29);
        P.displayText(Timp, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect); 
         while (!P.displayAnimate());
    }

    //Serial.println(Animation);
       i= i+1; 
       if (i > 5) 
       {
         i=1;
       }; 
 
}
 


Post a Comment

0 Comments