Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <TimeLib.h>
  2. #include <LiquidCrystal.h>
  3.  
  4. // initialize the library with the numbers of the interface pins
  5. LiquidCrystal lcd(12,11,5,4,3,2);
  6. char *pasar[] ={"Wage  ", "Kliwon", "Legi  ", "Paing ", "Pon   "};
  7. char *hari[] ={"Kamis ", "Jumat ", "Sabtu ", "Minggu  ", "Senin ", "Selasa", "Rabu  "};
  8. int maxday[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  9. byte p1[8] = {
  10.   0x10,
  11.   0x10,
  12.   0x10,
  13.   0x10,
  14.   0x10,
  15.   0x10,
  16.   0x10,
  17.   0x10};
  18.  
  19. byte p2[8] = {
  20.   0x18,
  21.   0x18,
  22.   0x18,
  23.   0x18,
  24.   0x18,
  25.   0x18,
  26.   0x18,
  27.   0x18};
  28.  
  29. byte p3[8] = {
  30.   0x1C,
  31.   0x1C,
  32.   0x1C,
  33.   0x1C,
  34.   0x1C,
  35.   0x1C,
  36.   0x1C,
  37.   0x1C};
  38.  
  39. byte p4[8] = {
  40.   0x1E,
  41.   0x1E,
  42.   0x1E,
  43.   0x1E,
  44.   0x1E,
  45.   0x1E,
  46.   0x1E,
  47.   0x1E};
  48.  
  49. byte p5[8] = {
  50.   0x1F,
  51.   0x1F,
  52.   0x1F,
  53.   0x1F,
  54.   0x1F,
  55.   0x1F,
  56.   0x1F,
  57.   0x1F};
  58. int detik=10;
  59. int menit=19;
  60. int jam=17;
  61. int tanggal=28;
  62. int bulan=6;
  63. int tahun=2016;
  64. int blinkState = LOW;
  65. unsigned long timer1;
  66. unsigned long timer2; //update detik1
  67. int curX;
  68. int curY;
  69. int set=6;
  70.  
  71.  
  72.  
  73. void setup() {
  74.   // set up the LCD's number of columns and rows:
  75.   pinMode(A2,INPUT);
  76.   pinMode(A1,INPUT);
  77.   pinMode(A0,INPUT);
  78.   lcd.createChar(1, p1);
  79.   lcd.createChar(2, p2);
  80.   lcd.createChar(3, p3);
  81.   lcd.createChar(4, p4);
  82.   lcd.createChar(5, p5);
  83.   lcd.begin(16, 2);
  84.   loadanim();
  85.   // Print a message to the LCD.
  86.   setTime(jam, menit, detik, tanggal, bulan, tahun);
  87. }
  88.  
  89. void loop() {
  90.   //variable here
  91.   unsigned long currentMillis = millis();
  92.   int t1 = digitalRead(A0);  //tombol setting
  93.   int t2 = digitalRead(A1);  // tombol Up
  94.   int t3 = digitalRead(A2);  // tombol down
  95.  
  96.   detik=second();
  97.   menit=minute();
  98.   jam=hour();
  99.   tanggal=day();
  100.   bulan=month();
  101.   tahun=year();
  102.    
  103.   //tombol setting
  104.   if (t3 == HIGH){
  105.        set = set +1;
  106.        delay(250);
  107.        if (set > 6) {
  108.          set=0;
  109.        }
  110.   }
  111.  
  112.   //setting waktu kedip kedip
  113.   if(currentMillis - timer1 > 300) {
  114.      timer1 = currentMillis;  
  115.     if (blinkState == LOW){
  116.       blinkState = HIGH;  
  117.     }
  118.     else {
  119.       blinkState = LOW;
  120.     }
  121.   }
  122.  
  123.  
  124.  
  125.   //setting posisi kedip2
  126.   if (set == 0) {
  127.     curX = 0;
  128.     curY = 0;
  129.     if (t1 == HIGH){
  130.       tanggal = tanggal +1;
  131.       delay(100);
  132.       if (tanggal > maxday[bulan] ) {
  133.         tanggal=1;
  134.       }
  135.     }
  136.     if (t2 == HIGH){
  137.       tanggal = tanggal -1;
  138.       delay(100);
  139.       if (tanggal < 1 ) {
  140.         tanggal=maxday[bulan];
  141.       }
  142.     }
  143.     setTime(jam, menit, detik, tanggal, bulan, tahun);  
  144.   }
  145.   if (set == 1) {
  146.     curX = 3;
  147.     curY = 0;
  148.     if (t1 == HIGH){
  149.       bulan = bulan +1;
  150.       delay(100);
  151.       if (bulan > 12 ) {
  152.         bulan=1;
  153.       }
  154.     }
  155.     if (t2 == HIGH){
  156.       bulan = bulan -1;
  157.       delay(100);
  158.       if (bulan < 1 ) {
  159.         bulan=12;
  160.       }
  161.     }
  162.     setTime(jam, menit, detik, tanggal, bulan, tahun);
  163.   }
  164.   if (set == 2) {
  165.     curX = 6;
  166.     curY = 0;
  167.     if (t1 == HIGH){
  168.       tahun = tahun +1;
  169.       delay(100);
  170.       if (tahun > 3000 ) {
  171.         tahun=2000;
  172.       }
  173.     }
  174.     if (t2 == HIGH){
  175.       tahun = tahun -1;
  176.       delay(100);
  177.       if (tahun < 2000 ) {
  178.         tahun=3000;
  179.       }
  180.     }
  181.     setTime(jam, menit, detik, tanggal, bulan, tahun);
  182.   }
  183.   if (set == 3) {
  184.     curX = 0;
  185.     curY = 1;
  186.     if (t1 == HIGH){
  187.       jam = jam +1;
  188.       delay(100);
  189.       if (jam > 23 ) {
  190.         jam=0;
  191.       }
  192.     }
  193.     if (t2 == HIGH){
  194.       jam = jam -1;
  195.       delay(100);
  196.       if (jam < 0 ) {
  197.         jam=23;
  198.       }
  199.     }
  200.     setTime(jam, menit, detik, tanggal, bulan, tahun);
  201.   }
  202.   if (set == 4) {
  203.     curX = 3;
  204.     curY = 1;
  205.     if (t1 == HIGH){
  206.       menit = menit +1;
  207.       delay(100);
  208.       if (menit > 59 ) {
  209.         menit=0;
  210.       }
  211.     }
  212.     if (t2 == HIGH){
  213.       menit = menit -1;
  214.       delay(100);
  215.       if (menit < 0 ) {
  216.         menit=59;
  217.       }
  218.     }
  219.     setTime(jam, menit, detik, tanggal, bulan, tahun);
  220.   }
  221.   if (set == 5) {
  222.     curX = 6;
  223.     curY = 1;
  224.     if (t1 == HIGH){
  225.       detik = detik +1;
  226.       delay(100);
  227.       if (detik > 59 ) {
  228.         detik=0;
  229.       }
  230.     }
  231.     if (t2 == HIGH){
  232.       detik = detik -1;
  233.       delay(100);
  234.       if (detik < 0 ) {
  235.         detik=59;
  236.       }
  237.     }
  238.     setTime(jam, menit, detik, tanggal, bulan, tahun);
  239.   }
  240.   if (blinkState == LOW) {
  241.     if (set != 6){
  242.       lcd.setCursor(curX,curY);
  243.       lcd.print("  ");
  244.     }
  245.   }
  246.  
  247.  
  248.   //tampilkan jam kalender
  249.   if (blinkState == HIGH) {
  250.   lcd.setCursor(0, 0);
  251.   if (tanggal < 10) lcd.print('0');
  252.   lcd.print(tanggal);
  253.   lcd.print("/");
  254.   if (bulan < 10) lcd.print('0');
  255.   lcd.print(bulan);
  256.   lcd.print("/");
  257.   lcd.print(tahun-2000); //tampilkan tahun dua digit saja
  258.  
  259.   lcd.setCursor(0,1);
  260.   if (jam < 10) lcd.print('0');
  261.   lcd.print(jam);
  262.   lcd.print(":");
  263.   if (minute() < 10) lcd.print('0');
  264.   lcd.print(menit);
  265.   lcd.print(":");
  266.   if (second() < 10) lcd.print('0');
  267.   lcd.print(detik);
  268.   lcd.print("  ");
  269.   lcd.setCursor(10, 0);
  270.   lcd.print(hari[jumlahhari()%7]);  //tampilkan Hari
  271.   lcd.setCursor(10, 1);
  272.   //lcd.write(0xC2);
  273.   lcd.print(pasar[jumlahhari()%5]); //Tampilkan Pasaran
  274.   }
  275.   // end //tampilkan jam kalender
  276.  
  277. }
  278. // digunakan untuk menghitung hari pasaran
  279. int jumlahhari(){  
  280.   int d= day();
  281.   int m= month();
  282.   int y= year();
  283.   int hb[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
  284.   int ht = (y - 1970) * 365 - 1;
  285.   int hs = hb[m - 1] + d;
  286.   int kab = 0;
  287.   int i;
  288.   if(y % 4 == 0) {
  289.     if(m > 2) {
  290.     hs++;
  291.     }
  292.   }
  293.   for(i = 1970; i < y; i++) {
  294.     if(i % 4 == 0) {
  295.     kab++;
  296.     }
  297.   }
  298.   return (ht + hs + kab);
  299. }
  300.  
  301. void loadanim(){
  302.   lcd.print("     LOADING");
  303.   lcd.setCursor(0,1);
  304.   for (int loadbar = 0; loadbar < 16; loadbar++) {
  305.     lcd.setCursor(loadbar,1);  
  306.     lcd.setCursor(loadbar,1);
  307.     lcd.write(1);
  308.     delay(10);
  309.     lcd.setCursor(loadbar,1);
  310.     lcd.write(2);
  311.     delay(10);
  312.     lcd.setCursor(loadbar,1);
  313.     lcd.write(3);
  314.     delay(10);
  315.     lcd.setCursor(loadbar,1);
  316.     lcd.write(4);
  317.     delay(10);
  318.     lcd.setCursor(loadbar,1);
  319.     lcd.write(5);
  320.     delay(10);
  321.   }
  322.   delay(500);
  323.   lcd.clear();
  324. }