Wednesday, November 4, 2020

[Arduino] - Jam digital dan running text dengan LED Max7219

 [Arduino] - Jam digital dan running text dengan LED Max7219

 




#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Wire.h>                        // DS3231clock
#include "RTClib.h"                      // DS3132 clock

/* JAM MEJA DIGITAL DENGAN RUNNING TEXT TGL
 *  KOMPONEN
 *  - ARDUINO
 *  - RTC DS 3231
 *  MODIFIED : APLIKASI-HEBAT STDUIO
 *  DATE MODIFIED : 4 NOV 2020
 */

//init
RTC_DS3231 rtc3231;

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

//const uint8_t SPEED_IN = A5;
//const uint8_t DIRECTION_SET = 8;  // change the effect
//const uint8_t INVERT_SET = 9;     // change the invert


//const uint8_t SPEED_DEADBAND = 5;

uint8_t scrollSpeed = 60;    // default frame delay value

textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 20; // keceptan running text in milliseconds

// Global message buffers shared by Serial and Scrolling functions
#define  BUF_SIZE  175
//int pjg=myString.length();
char curMessage[BUF_SIZE] = { "" };
char newMessage[BUF_SIZE] = { " "};

char c[100];
 
int tahun;
int bulan;
int tgl;
int jam;
int menit;
int detik;
int blink=0;
int blink1=0;
int dayoffweek;
String s;

String Hari[7] = {
  "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"
};

bool newMessageAvailable = true;

void setup()
{

  rtc3231.begin();
  P.begin();
  P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);

  P.setIntensity(0);
  // Clear the display:
  P.displayClear();
  //setting jam pertama kali
  //rtc3231.adjust(DateTime(2020, 11, 2, 5, 36, 0));
 
}

void loop()
{
//P.setTextAlignment(PA_CENTER);
get_time();


//int detik=29;

s=Hari[dayoffweek] + " TGL "+ Konversi(tgl)+"-"+ Konversi(bulan)+ "-"+ Konversi(tahun)+" JAM "+ Konversi(jam)+ ":"+ Konversi(menit)+"          ";
s.toUpperCase();
s.toCharArray(c, s.length()+1);
//P.displayReset();

//readSerial();
if (blink<=1)
{
  if (P.displayAnimate())
  {
    if (newMessageAvailable)
    {
     //strcpy(curMessage, newMessage);
      strcpy(curMessage, c);
      newMessageAvailable = false;
    }else {
      blink++;
      //P.displayClear();
      newMessageAvailable = true;
      P.displayText("welcome", PA_CENTER, scrollSpeed, 1000, PA_OPENING_CURSOR,PA_OPENING_CURSOR);
      P.displayReset();
      
      }

    
    P.displayReset();
  }
 

} else
{
  blink++;
  if (blink1==0)
  {
  P.print(Konversi(jam)+ ":"+ Konversi(menit));
  blink1=1;
  } else
  {
    P.print(Konversi(jam)+ " "+ Konversi(menit));
    blink1=0;
  }
  delay(1000);


 
  if( blink>=30) {
    blink=0;P.displayClear();
    newMessageAvailable = true;
    P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
  }
}


}

String Konversi(int sInput) {
  if (sInput < 10)
  {
    return"0" + String(sInput);
  }
  else
  {
    return String(sInput);
  }
}

void get_time()
{
  DateTime now= rtc3231.now();
  //save time to array
  tahun= now.year();
  bulan = now.month();
  tgl = now.day();
  dayoffweek = now.dayOfTheWeek(); //returns 0-6 where 0 = Sunday
  jam = now.hour();
  menit = now.minute();
  detik = now.second();
}

Video demo

Hasil Program Arduino




5 comments:

  1. Assalaamualaikum.
    saya mau tanya Bang. setiap sy upload selalu tidak berhasil, comentarnya Problem uploading begitu. kira kira kesalahan ada dimana ya ?

    ReplyDelete
  2. Asalamuailaikum.buff size itu fungsi nya buat apa ya?

    ReplyDelete
  3. Assalamualaikum bg, kalau untuk board LP10 bagaimana menyesuaikan program nya ke matrix nya?

    ReplyDelete

Pemrograman Running text P10 RGB dengan Arduino Nano

Pemrograman Running text P10 RGB dengan Arduino Nano PIN CONNECTION P10 RGB DENGAN ARDUINO NANO/UNO Source code arduino p10 RGB  #include &q...