Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_DS1307 0
- #include <MD_Parola.h>
- #include <MD_MAX72xx.h>
- #include <SPI.h>
- #include "Font7Seg.h"
- #define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
- #define MAX_CLK_ZONES 2
- #define ZONE_SIZE 8
- #define MAX_DEVICES (MAX_CLK_ZONES * ZONE_SIZE)
- #define ZONE_UPPER 1
- #define ZONE_LOWER 0
- #define CLK_PIN 13
- #define DATA_PIN 11
- #define CS_PIN 10
- #if USE_DS1307
- #include <MD_DS1307.h>
- #include <Wire.h>
- #endif
- MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
- #define SPEED_TIME 75
- #define PAUSE_TIME 0
- #define MAX_MESG 6
- #define DEBUG 0
- char szTimeL[MAX_MESG]; // mm:ss\0
- char szTimeH[MAX_MESG];
- void getTime(char *psz, bool f = true){
- #if USE_DS1307
- RTC.readTime();
- sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
- #else
- uint16_t h, m;
- m = millis()/1000;
- h = (m/60) % 24;
- m %= 60;
- sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
- #endif
- }
- void createHString(char *pH, char *pL)
- {
- for (; *pL != '\0'; pL++)
- *pH++ = *pL | 0x80; // offset character
- *pH = '\0'; // terminate the string
- }
- void setup(void)
- {
- P.begin(MAX_CLK_ZONES);
- P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
- P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES - 1);
- P.setFont(numeric7SegDouble);
- P.setCharSpacing(P.getCharSpacing() * 2);
- P.setZoneEffect(ZONE_UPPER, true, 2);
- P.setZoneEffect(ZONE_LOWER, false, 0);
- P.displayZoneText(ZONE_LOWER, szTimeL, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
- P.displayZoneText(ZONE_UPPER, szTimeH, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
- #if USE_DS1307
- RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
- RTC.control(DS1307_12H, DS1307_OFF);
- #endif
- }
- void loop(void)
- {
- static uint32_t lastTime = 0; // millis() memory
- static bool flasher = false; // seconds passing flasher
- P.displayAnimate();
- if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_UPPER))
- {
- if (millis() - lastTime >= 1000)
- {
- lastTime = millis();
- getTime(szTimeL, flasher);
- createHString(szTimeH, szTimeL);
- flasher = !flasher;
- P.displayReset();
- P.synchZoneStart();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement