Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <bitBangedSPI.h>
- #include <MAX7219_Dot_Matrix.h>
- #include <Wire.h>
- #include "RTClib.h"
- #define Y now.year()
- #define M now.month()
- #define D now.day()
- #define HD daysOfTheWeek[now.dayOfTheWeek()]
- #define H now.hour()
- #define m now.minute()
- #define s now.second()
- #define bHours 7
- int hours=0;
- const byte chips = 8;
- // 12 chips (display modules), hardware SPI with load on D10
- MAX7219_Dot_Matrix display (chips, 10); // Chips / LOAD
- char message [100];
- char waktu [100];
- char tgl [100];
- /*5v Arduino —- VCC Dot Matrix
- GND Arduino —- GND Dot Matrix
- 13 Arduino —– CLK Dot Matrix
- 10 Arduino —– CS Dot Matrix
- 11 Arduino —– DIN Dot Matrix*/
- #if defined(ARDUINO_ARCH_SAMD)
- // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
- #define Serial SerialUSB
- #endif
- RTC_DS3231 rtc;
- char daysOfTheWeek[7][12] = {"Ahad", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"};
- void setup (){
- display.begin ();
- #ifndef ESP8266
- while (!Serial); // for Leonardo/Micro/Zero
- #endif
- Serial.begin(57600);
- if (! rtc.begin()) {
- Serial.println("Couldn’t find RTC");
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC is NOT running!");
- // following line sets the RTC to the date & time this sketch was compiled
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- }
- pinMode(bHours,INPUT_PULLUP);
- } //END Set Up
- unsigned long lastMoved = 0;
- unsigned long MOVE_INTERVAL = 10; // mS
- unsigned long lastMoved1 = 0;
- unsigned long MOVE_INTERVAL1 = 1; // mS
- int messageOffset;
- int messageOffset1;
- void updateDisplay (){
- DateTime now = rtc.now();
- sprintf (message, "Jual Pulsa");
- display.sendSmooth (message, messageOffset);
- //sprintf (tgl, "%d-%d-%d",D,M,Y); //tgl-bulan-tahun
- // next time show one pixel onwards
- if (messageOffset++ >= (int) (strlen (message) * 8))
- messageOffset = - chips * 8;
- } // end of updateDisplay
- void updateJam (){
- DateTime now = rtc.now();
- int h=now.hour();
- int stateHours = digitalRead(bHours);
- if(stateHours==LOW){
- hours=hours+1;
- h=h+1;
- Serial.println(h);
- }
- sprintf (waktu, "%d:%d:%d", h,m,s); //waktu
- if(h<10)
- sprintf (waktu, "0%d:%d:%d", h,m,s); //ubah jam
- if(m<10)
- sprintf (waktu, "%d:0%d:%d", h,m,s);
- if(s<10)
- sprintf (waktu, "%d:%d:0%d", h,m,s);
- if(m<10 && h<10 && s<10)
- sprintf (waktu, "0%d:0%d:0%d", h,m,s);
- else if(m<10 && h<10)
- sprintf (waktu, "0%d:0%d:%d", h,m,s);
- else if(m<10 && s<10)
- sprintf (waktu, "%d:0%d:0%d", h,m,s);
- else if(h<10 && s<10)
- sprintf (waktu, "0%d:%d:0%d", h,m,s);
- display.sendString(waktu);
- } // end of updateJam
- int state=0;
- void loop (){
- // update display if time is up
- if(millis() - lastMoved >= MOVE_INTERVAL && state==0){
- updateJam();
- //lastMoved = millis ();
- state=0;
- }else if(millis() - lastMoved >= MOVE_INTERVAL1 && state==1){
- //updateJam();
- updateDisplay ();
- lastMoved = millis();
- state=0;
- }/**/
- } // end of loop
Add Comment
Please, Sign In to add comment