Saturday, January 7, 2023

Running text jam digital dengan max 7219 dan Nodemcu esp8266 lolin v3 lua ch340G



#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 : 8 Jan 2023 

 *  

RTC3231   -------->       NODEMCU LOLIN V3 LUA CH340G ESP8266 IOT WIFI   

SCL                       D1

SDA                       D2

VCC                       3.3V

GND                      GND



MAX7219   ------>      NODEMCU LOLIN V3 LUA CH340G ESP8266 IOT WIFI 

CS                           8

CLK                          7

DIN                          6

VCC                          3.3V

GND                         GND


 */


//init

RTC_DS3231 rtc3231;


#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

#define MAX_DEVICES 4
#define CLK_PIN   D7 

#define DATA_PIN  D6  
#define CS_PIN    D8 


MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);



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 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()

{

  //pinMode(1, OUTPUT);

  

 // Wire.begin(1,2);

  rtc3231.begin();

  P.begin();

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


  P.setIntensity(5);

  // Clear the display:

  P.displayClear();

  //setting jam pertama kali

 // rtc3231.adjust(DateTime(2023, 1, 8, 9, 9, 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();

}




1 comment:

  1. Setting tanggal bgaimana ga bisa pakai wifi ya mas biar akurat

    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...