Tuesday, December 25, 2018

Cara Menggunakan Motor Stepper Dengan Arduino


Program :

//diy ALC
//steps = Number of steps in One Revolution  * Gear ratio   .
//steps= (360°/5.625°)*64"Gear ratio" = 64 * 64 =4096

#define IN1  8
#define IN2  9
#define IN3  10
#define IN4  11
int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left = 4095;
long time;
void setup()
{
  Serial.begin(9600);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  // delay(1000);

}
void loop()
{
  if (Direction == true)Serial.println("Berlawanan Arah Jarum Jam");
  else Serial.println("Searah Jarum Jam");

  while (steps_left > 0) {
    currentMillis = micros();
    if (currentMillis - last_time >= 1000) {
      stepper(1);
      time = time + micros() - last_time;
      last_time = micros();
      steps_left--;
    }
  }
  //Serial.println(time);
  Serial.println("Wait...!");
  delay(2000);
  Direction = !Direction;
  steps_left = 4095;

}

void stepper(int xw) {
  for (int x = 0; x < xw; x++) {
    switch (Steps) {
      case 0:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      case 1:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, HIGH);
        break;
      case 2:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 3:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 4:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 5:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 6:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 7:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      default:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
    }
    SetDirection();
  }
}
void SetDirection() {
  if (Direction == 1) {
    Steps++;
  }
  if (Direction == 0) {
    Steps--;
  }
  if (Steps > 7) {
    Steps = 0;
  }
  if (Steps < 0) {
    Steps = 7;
  }
}

Tuesday, October 16, 2018

Coin Acceptor With Arduino | Sensor Koin Dengan Arduino



Program:

/*
  Amar Lakar Cengkal
  diy ALC
*/

#define ten_sens 8
#define twenty_sens 9
#define fifty_sens 10

//initialization
int coin=0;
int pulse=0;
int total=0;
int RM=0;

//read coin value
void coin_value()
{
  pulse=pulse+1;
}

void setup()
{
  Serial.begin(9600);
  pinMode(2,INPUT);
  pinMode(ten_sens,OUTPUT);
  pinMode(twenty_sens,OUTPUT);
  pinMode(fifty_sens,OUTPUT);
  Serial.println("Ready to be collected");
}

void loop()
{
  if (digitalRead(2) == HIGH)
  {
    attachInterrupt(0, coin_value, FALLING);
    delay(300);
    if(pulse==2)
    {
      Serial.println("500 kuning");
      coin=500; //500
      digitalWrite(fifty_sens,HIGH);
      delay(1);
    }
    if(pulse==5)
    {
      Serial.println("500 silver");
      coin=500; //500
      digitalWrite(twenty_sens,HIGH);
      delay(1);
    }
    if(pulse==10)
    {
      Serial.println("1000 chrome");
      coin=1000; //1000
      digitalWrite(ten_sens,HIGH);
      delay(1);
    }
  }
  digitalWrite(ten_sens,LOW);
  digitalWrite(twenty_sens,LOW);
  digitalWrite(fifty_sens,LOW);
  coin=0;
  pulse=0;
}

Tuesday, September 25, 2018

Youtube Movie Maker Full Crack


Download Aplikasi Klik Disini

Friday, August 3, 2018

Tutorial Cara Menggunakan Sensor Arus ACS712 Di Arus AC



Program:

#include "ACS712.h"

/*
  This example shows how to measure the power consumption
  of devices in 230V electrical system
  or any other system with alternative current
*/

// We have 30 amps version sensor connected to A0 pin of arduino
// Replace with your version if necessary
ACS712 sensor(ACS712_30A, A0);

void setup() {
  Serial.begin(9600);

  // calibrate() method calibrates zero point of sensor,
  // It is not necessary, but may positively affect the accuracy
  // Ensure that no current flows through the sensor at this moment
  // If you are not sure that the current through the sensor will not leak during calibration - comment out this method
  Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
  sensor.calibrate();
  Serial.println("Done!");
}

void loop() {
  // We use 230V because it is the common standard in European countries
  // Change to your local, if necessary
  float U = 230;

  // To measure current we need to know the frequency of current
  // By default 50Hz is used, but you can specify desired frequency
  // as first argument to getCurrentAC() method, if necessary
  float I = sensor.getCurrentAC();

  // To calculate the power we need voltage multiplied by current
  float P = U * I;

  Serial.println(String("I = ") + I + " A");
  Serial.println(String("P = ") + P + " Watts");

  delay(1000);
}

Thursday, January 11, 2018

Membuat Jam Digital Menggunakan Module P10 Dan Arduino V.5

Pogram:

/*----------------------------------------------------------------------
   Project    : Jam Digital DotMatrix Display
   Author     : diy ALC
   Version    : 3.0
  ----------------------------------------------------------------------*/
// Menyisipkan File Library
#include <Wire.h>
#include <RTClib.h>
#include <SPI.h>
#include <TimerOne.h>
#include <DMD1.h>
#include <SystemFont5x7.h>
#include <System6x7.h>
#include <BigNumber.h>
#include <stdio.h>
#include <DS1302.h>

byte SW0 = A4; 
byte SW1 = A5; 
byte SW2 = 4; 
unsigned int tumbal;
unsigned int tumbal2;
int Button;
boolean mboh;
int timer1 = 1;
int  delay_now;
int delay_past;
boolean showMode = 0;
char datToString[2];

// Mendifinisakan Fungsi
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
#define Panjang 1
#define Lebar 1

// Deklarasi Fungsi
DMD dmd(Panjang, Lebar);                  // Panjang x Lebar

namespace {

const int kCePin   = A2;  // Chip Enable
const int kIoPin   = A1;  // Input/Output
const int kSclkPin = A0;  // Serial Clock

DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Minggu";
    case Time::kMonday: return "Senin";
    case Time::kTuesday: return "Selasa";
    case Time::kWednesday: return "Rabu ";
    case Time::kThursday: return "Kamis";
    case Time::kFriday: return "Jum'at";
    case Time::kSaturday: return "Sabtu";
  }
  return "(unknown day)";
}


void Show_TwoDigit(int posX, int posY, double value) 
{
  if (value < 10)
  {
    dtostrf(value, 1, 0, datToString);
    dmd.drawString(posX, posY, "0", 1, GRAPHICS_NORMAL);
    dmd.drawString(posX + 7, posY, datToString, 1, GRAPHICS_NORMAL);
  }
  else
  {
    dtostrf(value, 2, 0, datToString);
    dmd.drawString(posX, posY, datToString, 2, GRAPHICS_NORMAL);
  }
}

void ShowTime() //show small time
{
  Time t = rtc.time();
  int det = t.sec % 2;
  if (det != 0)
    dmd.drawString(16, 0, ":", 1, GRAPHICS_NORMAL); //blink dot
  else
    dmd.drawString(16, 0, ":", 1, GRAPHICS_NOR);

  Show_TwoDigit (2, 0, t.hr);                                         // hsow hour
  Show_TwoDigit (19, 0, t.min);                                      //show minute
}

void drawText( String dispString )
{
  char newString[128];
  int sLength = dispString.length();
  dispString.toCharArray( newString, sLength + 1 );
  dmd.drawMarquee( newString , sLength , 31 , 8);
  long timer = millis();
  boolean ret = false;
  dmd.clearScreen(true);
  Time t = rtc.time();
  while ( !ret ) {
    if ( ( timer + 40 ) < millis() )
    {
      Time t = rtc.time();
      ShowTime();
      ret = dmd.stepSplitMarquee(8, 15);
      timer = millis();

    }

  }
  dispString = "";
  showMode = false;
  delay_past = millis();
  dmd.clearScreen(true);
}

void TwoDigit(int digit, String &hasilDigit) 
{
  hasilDigit = "";
  if (digit < 10)
  {
    hasilDigit += "0";
    hasilDigit += digit;
  }
  else
  {
    hasilDigit += digit;
  }
}

void scrollDate()
{
  String  text2, textSmntara ;
  Time t = rtc.time();
  String twodigit;
  textSmntara = "<-MOH.SJAHRI <-KAMLAHWATI <-KURNIAWAN KAMARI <-INDRA WAHYUDI <-AMAR ANSHORI      "; ///u can add  text here
  text2 += textSmntara;

  if (dayAsString(t.day) == "Minggu") text2 += "Minggu";
  else if (dayAsString(t.day) == "Senin") text2 += "Senin";
  else if (dayAsString(t.day) == "Selasa") text2 += "Selasa";
  else if (dayAsString(t.day) == "Rabu ") text2 += "Rabu";
  else if (dayAsString(t.day) == "Kamis") text2 += "Kamis";
  else if (dayAsString(t.day) == "Jum'at") text2 += "Jum'at";
  else if (dayAsString(t.day) == "Saptu") text2 += "Saptu";
  else text2 += "Kosong";

  Serial.print("gulung");
  Serial.println(dayAsString(t.day));

  text2 += "-";
  //Time c = rtc.time();
  TwoDigit(t.date, twodigit);
  text2 += twodigit;
  text2 += "-";
  //  Time c = rtc.time();
  TwoDigit(t.mon, twodigit);
  text2 += twodigit;
  text2 += "-";
  // Time c = rtc.time();
  dtostrf(t.yr, 4, 0, datToString);
  text2 += datToString;
  drawText (text2);

}



void ShowTimeBig()//show big time
{
  String bigDigit = "";
  dmd.selectFont(BigNumber);
  Time t = rtc.time();
  int j;
  int det = t.sec % 2;
  if (det != 0) {
    dmd.drawCircle(16, 5, 1, GRAPHICS_NORMAL); //blink clock dot
    dmd.drawCircle(16, 10, 1, GRAPHICS_NORMAL);
  }
  else
  { dmd.drawCircle(16, 5, 1, GRAPHICS_NOR);
    dmd.drawCircle(16, 10, 1, GRAPHICS_NOR);
  }
  j = t.hr;
  TwoDigit(j, bigDigit);
  bigDigit.toCharArray(datToString, 3);
  dmd.drawString(1, 0, datToString, 2, GRAPHICS_NORMAL); //show big hour

  j = t.min;
  TwoDigit(j, bigDigit);
  bigDigit.toCharArray(datToString, 3);
  dmd.drawString(19, 0, datToString, 2, GRAPHICS_NORMAL); //show big minute
}



double moreLess24(double value)   //make sure a value is between 0 and 24
{
  while (value > 24 || value < 0)
  {
    if (value > 24)
      value -= 24;
    else if (value < 0)
      value += 24;
  }
  return value;
}

void doubleToHrMin(double number, int &hours, int &minutes)//convert the double number to Hours and Minutes
{
  hours = floor(moreLess24(number));
  minutes = floor(moreLess24(number - hours) * 60);
}

byte decToBcd(byte val) {
  return ((val / 10 * 16) + (val % 10));
}

void ReadButton()
{

  if ((digitalRead(SW1) == 0) && (digitalRead(SW2) == 0))
  { Button = 4;
    //delay(50);
    Serial.println("tombol 4");
  }
  else if (digitalRead(SW0) == 0)
  { Button = 1; // minus button
    //delay(50);
    Serial.println("tombol 1");
  }
  else  if (digitalRead(SW1) == 0)
  { Button = 2; //  plus button
    //delay(50);
    Serial.println("tombol 2");
  }
  else if (digitalRead(SW2) == 0)
  { Button = 3; // menu button
    //delay(50);
    Serial.println("tombol 3");
  }
  else Button = 0; Serial.println("tombol 0");

}

void softReset()
{
  asm volatile ("  jmp 0");
}



void seting()
{
  char modesetup[6][9] = {"Jam  ", "Mnt  ", "Tgl  ", "Bln  ", "Thn  ", "Hri  "}; //Set Waktu Dan Tanggal
  Time t = rtc.time();
  byte sminutes = t.min;
  byte shours = t.hr;
  byte tgl = t.day;
  byte bln = t.mon;
  byte th = t.yr - 2000;
  byte hr;

  Serial.println(sminutes);
  Serial.println(shours);
  Serial.println(tgl);
  Serial.println(bln);
  Serial.println(th);

  if (dayAsString(t.day) == "Minggu") hr = 1;
  else if (dayAsString(t.day) == "Senin") hr = 2;
  else if (dayAsString(t.day) == "Selasa") hr = 3;
  else if (dayAsString(t.day) == "Rabu ") hr = 4;
  else if (dayAsString(t.day) == "Kamis") hr = 5;
  else if (dayAsString(t.day) == "Jum'at") hr = 6;
  else if (dayAsString(t.day) == "Saptu") hr = 7;
  else hr = 15;

  Serial.print(hr);
  Serial.print("-");
  Serial.println(dayAsString(t.day));

  dmd.clearScreen( true );


  while ((tumbal != 0) || (Button == 2) || (Button == 3)) {
    delay(500);
    dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
    ReadButton();
    if (tumbal > 6)
    {
      tumbal = 1;
    }

    Serial.print("tumbalswitch: ");
    Serial.println(tumbal);
    Serial.print("tumbal2: ");
    Serial.println(tumbal2);



    switch (tumbal) {

      case 1: {                //set jam
          if (Button == 2) {
            dmd.clearScreen( true );
            shours++;
            if (shours >= 24) shours = 0;
          }
          if (Button == 3) {
            dmd.clearScreen( true );
            if (shours <= 0)shours = 24;
            shours--;
          }
          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          dmd.drawString(0, 8, "     ", 5, GRAPHICS_NORMAL);
          Show_TwoDigit (0, 8, shours);

          Serial.print("jambutton: ");
          Serial.println(Button);

        }
        break;

      case 2: {    //set menit
          if (Button == 2) {
            dmd.clearScreen( true );
            sminutes++;
            if (sminutes >= 60) sminutes = 0;

          }
          if (Button == 3) {
            dmd.clearScreen( true );
            sminutes--;
            if (sminutes <= 0) sminutes = 59;

          }
          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          Show_TwoDigit (0, 8, sminutes);

          Serial.print("menitbutton: ");
          Serial.println(Button);
        }
        break;

      case 3: {    //tanggal
          if (Button == 2) {
            dmd.clearScreen( true );
            tgl++;
            if (tgl >= 31) tgl = 1;

          }
          if (Button == 3) {
            dmd.clearScreen( true );
            tgl--;
            if (tgl == 0) tgl = 31;
          }
          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          Show_TwoDigit (0, 8, tgl);
          Serial.print("tanggalbutton: ");
          Serial.println(Button);
        }
        break;

      case 4: {                //set bulan
          if (Button == 2) {
            dmd.clearScreen( true );
            bln++;
            if (bln >= 12) bln = 1;
          }
          if (Button == 3) {
            dmd.clearScreen( true );
            bln--;
            if (bln == 0)bln = 12;
          }
          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          Show_TwoDigit (0, 8, bln);

          Serial.print("bulanbutton: ");
          Serial.println(Button);
        }
        break;

      case 5: {    //set tahun
          if (Button == 2) {
            dmd.clearScreen( true );
            th++;
            if (th > 99) th = 0;
          }
          if (Button == 3) {
            dmd.clearScreen( true );
            th--;
            if (th < 0) th = 99;
          }
          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          Show_TwoDigit (0, 8, th);

          Serial.print("tahunbutton: ");
          Serial.println(Button);
        }
        break;

      case 6: {    //set hari
          if (Button == 2) {
            dmd.clearScreen( true );
            hr++;
            if (hr >= 8) hr = 1;
          }
          if (Button == 3) {
            dmd.clearScreen( true );
            hr--;
            if (hr <= 0) hr = 7;
          }

          dmd.drawString(0, 0, modesetup[tumbal - 1], 8, GRAPHICS_NORMAL);
          if (hr == 1) dmd.drawString(0, 8, "Minggu", 7, GRAPHICS_NORMAL);
          else if (hr == 2) dmd.drawString(0, 8, "Senin", 7, GRAPHICS_NORMAL);
          else if (hr == 3) dmd.drawString(0, 8, "Selasa", 7, GRAPHICS_NORMAL);
          else if (hr == 4) dmd.drawString(0, 8, "Rabu ", 7, GRAPHICS_NORMAL);
          else if (hr == 5) dmd.drawString(0, 8, "Kamis", 7, GRAPHICS_NORMAL);
          else if (hr == 6) dmd.drawString(0, 8, "Jum'at", 7, GRAPHICS_NORMAL);
          else if (hr == 7) dmd.drawString(0, 8, "Saptu", 7, GRAPHICS_NORMAL);

          Serial.print("haributton: ");
          Serial.println(Button);

        }
        break;
    }

    while (Button == 0)
    {
      ReadButton();

    } //wait for key pressed
    if (Button == 1)
    {
      int a;
      a++;
      if (a > 6)a = 1;
      Serial.print("a++; ");
      Serial.println(a);
      tumbal2 = tumbal = a;
      Serial.print("tumbal++; ");
      Serial.println(tumbal);
    }

    delay(100);
    if (Button == 4) {

      rtc.writeProtect(false);
      rtc.halt(false);
      th = th + 2000;
      Time t(th, bln, tgl, shours, sminutes, 00, hr);
      rtc.time(t);

      dmd.clearScreen( true );
      tumbal = 0;
      Serial.print("Button4: ");
      Serial.println(tumbal);
      delay(500);
      softReset();
      delay(500);
    }

  }
}

void setingJam()
{
  Serial.println("seting jam");
  ReadButton();
  delay(250);
  while ((Button != 0 ) || (tumbal != 0))
  {
    Serial.println("readbutton");
    ReadButton();
    delay(50);
    if (Button == 1)
    {
      tumbal = 1;
    }
    Serial.println("seting");
    seting();
  }
}

void printTime() {


  dmd.selectFont(System6x7);

  if (millis() <= 500)
  {
    setingJam();
  }
  delay_now = millis();
  if (delay_now - delay_past > 30000) {
    delay_past = delay_now;
    showMode = true;
  }
  if (!showMode)ShowTimeBig();
  else scrollDate();

}


}//namespace

void ScanDMD() {
  dmd.scanDisplayBySPI();
}

void setup() //////////////////////////////////////////////////////////////////////
{
  Serial.begin(9600);

  pinMode(SW0, INPUT_PULLUP);  // Set Time (for this use a slide switch)
  pinMode(SW1, INPUT_PULLUP);  // Set Date (for this use a slide switch)
  pinMode(SW2, INPUT_PULLUP);  // N.O. push button switch

  Timer1.initialize( 3000 );           
  Timer1.attachInterrupt( ScanDMD );

  dmd.clearScreen( true );  
  rtc.writeProtect(false);
  rtc.halt(false);
}

void loop() //////////////////////////////////////////////////////////
{

  printTime();


}

/////////////////////////////////////////////////////////////////////

Wednesday, January 10, 2018

Cara Menggunakan Sensor PH Meter (SKU: SEN0161) Dengan Arduino

Contoh Program:

#define SensorPin A0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex = 0;
void setup(void)
{
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  Serial.println("pH meter experiment!"); //Test the serial monitor
}
void loop(void)
{
  static unsigned long samplingTime = millis();
  static unsigned long printTime = millis();
  static float pHValue, voltage;
  if (millis()-samplingTime > samplingInterval)
  {
    pHArray[pHArrayIndex++] = analogRead(SensorPin);
    if (pHArrayIndex == ArrayLenth)pHArrayIndex = 0;
    voltage = avergearray(pHArray, ArrayLenth) * 5.0 / 1024;
    pHValue = 3.5 * voltage + Offset;
    samplingTime = millis();
  }
  if (millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
  {
    Serial.print("Voltage:");
    Serial.print(voltage, 2);
    Serial.print(" pH value: ");
    Serial.println(pHValue, 2);
    digitalWrite(LED, digitalRead(LED) ^ 1);
    printTime = millis();
  }
}
double avergearray(int* arr, int number) {
  int i;
  int max, min;
  double avg;
  long amount = 0;
  if (number <= 0) {
    Serial.println("Error number for the array to avraging!/n");
    return 0;
  }
  if (number < 5) { //less than 5, calculated directly statistics
    for (i = 0; i < number; i++) {
      amount += arr[i];
    }
    avg = amount / number;
    return avg;
  } else {
    if (arr[0] < arr[1]) {
      min = arr[0]; max = arr[1];
    }
    else {
      min = arr[1]; max = arr[0];
    }
    for (i = 2; i < number; i++) {
      if (arr[i] < min) {
        amount += min; //arr<min
        min = arr[i];
      } else {
        if (arr[i] > max) {
          amount += max; //arr>max
          max = arr[i];
        } else {
          amount += arr[i]; //min<=arr<=max
        }
      }//if
    }//for
    
    avg = (double)amount / (number-2);
  }//if
  return avg;
}

Monday, January 8, 2018

Membuat Running Teks Modul P10 Menggunakan Arduino Dan RTC


Cara Membuat Jam Digital Detik Bergeser Menggunakan Arduino Dengan Module LED Matrix P10


Program:

/*----------------------------------------------------------------------
 * Project    : Jam Digital DotMatrix Display Detik Geser
 * Author     : Amar Lakar Cengkal
 * Version    : 1.0
 * 
 ----------------------------------------------------------------------*/

#include <DMD2.h>         
#include <fonts/SystemFont5x7.h> 
#include <fonts/MyBigFont.h> 
#include <fonts/Arial_Black_16.h> 
#include <stdio.h>
#include <DS1302.h>

#define Panjang 1                        
#define Lebar 1 
#define max_char 50                        

SoftDMD dmd(Panjang, Lebar);                
char message[max_char];
char tahun[5];
char bulan[7];
char tanggal[7];
char jam[7];
char menit[7];
char detik[7];
char hari[7];
char tulisan[20];

char r_char;
byte asu= 0;
int i,r;
int a=0;
int taek=0;

namespace {

const int kCePin   = A2;  // Chip Enable
const int kIoPin   = A1;  // Input/Output
const int kSclkPin = A0;  // Serial Clock

DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Minggu";
    case Time::kMonday: return "Senin";
    case Time::kTuesday: return "Selasa";
    case Time::kWednesday: return "Rabu";
    case Time::kThursday: return "Kamis";
    case Time::kFriday: return "Jumat";
    case Time::kSaturday: return "Sabtu";
  }
  return "(unknown day)";
}
/////////////////////////////////////////////////////////////////////
void setjam()
{
     if(Serial3.available())
  {
    for(i=0; i<50; i++)
    {
    message[i] = '\0';
    }
    for(i=0; i<7; i++)
    {
      tahun[i] = '\0';
      bulan[i] = '\0';
      tanggal[i] = '\0';
      jam[i] = '\0';
      menit[i] = '\0';
      detik[i] = '\0';
      hari[i] = '\0';
    }
    for(i=0; i<20; i++)
    {
      tulisan[i] = '\0';
    }
    taek=0;
  }
   while(Serial3.available() > 0)
   {
    if(taek < (max_char-1)) 
    {
      r_char = Serial3.read();
      message[taek] = r_char;
      taek++;
      message[taek] = '\0';
    }
    r=1;
    
  }

  if(r==1)
  {
   if(message[0]=='%')
   {
    for(int i=0; i<20; i++)
    {
      if(message[i+1]=='&')
      {
       goto bawah; 
      }
      tulisan[i]=message[i+1];
    }
   }
    
    for(int i=0; i<24; i++)
    {
      if(message[i]=='#')
      {
        for(int j=0; j<24; j++)
        {
         i++;
         if(message[i]=='#')
         {
          for(int k=0; k<24; k++)
          {
           i++;
           if(message[i]=='#')
           {
            for(int l=0; l<24; l++)
            {
             i++;
             if(message[i]=='#')
             {
              for(int m=0; m<24; m++)
              {
               i++;
               if(message[i]=='#')
               {
                for(int n=0; n<24; n++)
                {
                 i++;
                 if(message[i]=='#')
                 {
                  for(int o=0; o<24; o++)
                  {
                   i++;
                   if(message[i]=='&')
                   { 
                    goto bawah;
                   } 
                   hari[o] = message[i];
                  }
                 }
                 detik[n] = message[i];
                }
               }
               menit[m] = message[i];
              }
             }
             jam[l] = message[i];
            }
           }
           tanggal[k] = message[i];
          }
         }
         bulan[j] = message[i];
          
        }
      }
      tahun[i] = message[i];
    }

bawah:        
    r=2;
    }

    if(r==2)
    {
      if(atoi(hari)==1)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kMonday); 
          rtc.time(t);
      }
      else if(atoi(hari)==2)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kTuesday); 
          rtc.time(t);
      }
      else if(atoi(hari)==3)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kWednesday); 
          rtc.time(t);
      }
      else if(atoi(hari)==4)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kThursday); 
          rtc.time(t);
      }
      else if(atoi(hari)==5)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kFriday); 
          rtc.time(t);
      }
      else if(atoi(hari)==6)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kSaturday); 
          rtc.time(t);
      }
      else if(atoi(hari)==7)
      {
          Time t(atoi(tahun), atoi(bulan), atoi(tanggal), atoi(jam), atoi(menit), atoi(detik), Time::kSunday); 
          rtc.time(t);
      }
    //Time t(2017, 1, 26, 21, 10, 50, Time::kSunday);
    //Time t(atoi(tahun), atoi(bulan), atoi(hari), atoi(jam), atoi(menit), atoi(detik), Time::kSunday);
    //rtc.time(t);
    r=0;
    }
}
/////////////////////////////////////////////////////////////////////
void printTime() {

  dmd.clearScreen();
  dmd.selectFont(SystemFont5x7);
  int g=0,h=0;;
  
  for(int i=-65;i<=50;i++)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  // snprintf(bufd, sizeof(bufd), "%02d",
  //         t.sec);

  snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( i, 9, bufd );
   delay(100);
   

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int i=50;i>=-65;i--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
 // snprintf(bufd, sizeof(bufd), "%02d",
  //         t.sec);

  snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);  

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( i, 9, bufd );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  }
setjam();
    for(int j=-65;j<=50;j++)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  snprintf(bufd, sizeof(bufd), "%s",
           day.c_str());

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( j, 9, bufd );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int j=50;j>=-65;j--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  snprintf(bufd, sizeof(bufd), "%s",
           day.c_str());

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( j, 9, bufd );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
    for(int j=-65;j<=50;j++)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  snprintf(bufd, sizeof(bufd), "%02d%s",
           t.sec, "sec.");

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( j, 9, bufd );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int j=50;j>=-65;j--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  snprintf(bufd, sizeof(bufd), "%02d%s",
           t.sec, "sec.");

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( j, 9, bufd );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int k=32;k>=-55;k--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  //snprintf(bufd, sizeof(bufd), "%02d%s",
  //         t.sec, "sec.");

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( k, 9, "KURNIAWAN" );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int k=32;k>=-40;k--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  //snprintf(bufd, sizeof(bufd), "%02d%s",
  //         t.sec, "sec.");

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( k, 9, "INDRA" );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
setjam();
  for(int k=32;k>=-40;k--)
  {
// Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  char bufd[50];
  snprintf(buf, sizeof(buf), "%02d:%02d",
           t.hr, t.min);
  //snprintf(bufd, sizeof(bufd), "%02d%s",
  //         t.sec, "sec.");

  //snprintf(bufd, sizeof(bufd), "%02d-%02d-%04d", t.date, t.mon, t.yr);

   dmd.clearScreen();
   //delay(5);
   dmd.drawString( g, 0, buf ); //x,y
   dmd.drawString( k, 9, "AMAR" );
   delay(100);

   if(h==0)
   {
    if(g==2) h=1;
    g++;
   }

   else if(h==1)
   {
    if(g==1) h=0;
    g--;
   }
  
  }
  
}

}  // namespace //////////////////////////////////////////////////////



void setup() //////////////////////////////////////////////////////////////////////
{
  // Setup DMD
  dmd.setBrightness(255);
  dmd.clearScreen();
  dmd.selectFont(SystemFont5x7);
  dmd.begin();
  
  rtc.writeProtect(false);
  rtc.halt(false);

  Serial3.begin(9600);

  tulisan[0]='x';
}

void loop() //////////////////////////////////////////////////////////
{

   printTime();
  
   dmd.clearScreen();
   dmd.selectFont(MyBigFont);
  
  if(a==0)
  {
setjam();  
  for(int k=33;k>=-120;k--)
  {
   
   dmd.clearScreen();
   dmd.drawString( k, 0, "RI");
   delay(55);
   
  }
setjam();
if(tulisan[0]!='x')
 {
  dmd.clearScreen();
  dmd.selectFont(Arial_Black_16);
  for(int k=33;k>=-240;k--)
  {  
   dmd.clearScreen();
   dmd.drawString( k, 0, tulisan);
   delay(55);   
  }
 }
   a=1;
  }

  else if(a==1)
  {
setjam();  
  for(int k=33;k>=-120;k--)
  {
   
   dmd.clearScreen();
   dmd.drawString( k, 0, "KAM");
   delay(55);
   
  }

setjam();
if(tulisan[0]!='x')
 {
  dmd.clearScreen();
  dmd.selectFont(Arial_Black_16);
  for(int k=33;k>=-240;k--)
  {  
   dmd.clearScreen();
   dmd.drawString( k, 0, tulisan);
   delay(55);   
  }
 }
   a=0;
  }
   
}