Last active
December 10, 2019 10:55
-
-
Save Electronza/787807ccb137670b19c395ac251fe240 to your computer and use it in GitHub Desktop.
Arduino binary clock - V1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************* | |
____ __ ____ ___ ____ ____ __ __ _ ____ __ | |
( __)( ) ( __)/ __)(_ _)( _ \ / \ ( ( \(__ ) / _\ | |
) _) / (_/\ ) _)( (__ )( ) /( O )/ / / _/ / \ | |
(____)\____/(____)\___) (__) (__\_) \__/ \_)__)(____)\_/\_/ | |
Project name: Arduino LED matrix binary clock | |
Project page: https://electronza.com/arduino-led-matrix-binary-clock | |
Description: This version shows each digit of the hours, minutes and seconds | |
as a binary number | |
********************************************************************/ | |
// Thus, 12:39:45 will be | |
// Hours | |
// 00000001 | |
// 00000010 | |
// Minutes | |
// 00000011 | |
// 00001001 | |
// Seconds | |
// 00000100 | |
// 00000101 | |
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib | |
#include <Wire.h> | |
#include "RTClib.h" | |
// Library for 8x8B click | |
#include "LedControl.h" | |
// The 8x8 click board is placed in mikroBUS socket #1 | |
LedControl lc=LedControl(11,13,10,1); | |
// RTC settings | |
RTC_DS1307 rtc; | |
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; | |
// Clock variables | |
// Look-up table to show binary values on the LED matrix | |
int myBinaryDisp[] = {B00000000, B10000000, B01000000, B11000000, B00100000, | |
B10100000, B01100000, B11100000, B00010000, B10010000}; | |
bool is_second = false; | |
void setup() { | |
// RTC Initialization | |
if (! rtc.begin()) { | |
while (1); | |
} | |
if (! rtc.isrunning()) { | |
// 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)); | |
} | |
/* | |
The MAX72XX is in power-saving mode on startup, | |
we have to do a wakeup call | |
*/ | |
lc.shutdown(0,false); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(0,4); | |
/* and clear the display */ | |
lc.clearDisplay(0); | |
// Set up interrupts | |
interrupts(); | |
// If the RTC is placed in mikroBUS socket #2 the interrupt pin is D3 | |
attachInterrupt(digitalPinToInterrupt(3), onesecond, RISING); | |
// CONFIGURE RTC for 1Hz square wave output | |
rtc.writeSqwPinMode(SquareWave1HZ); | |
} | |
void loop() { | |
if (is_second == true){ | |
update_display(); | |
is_second = false; | |
} | |
} | |
// This function updates the LED matrix | |
void update_display (void){ | |
// Read the RTC | |
DateTime now = rtc.now(); | |
// lc.clearDisplay(0);// clear screen | |
// update hours | |
// upper digit | |
int hh = now.hour() / 10; | |
lc.setColumn(0,0,myBinaryDisp[hh]); | |
//lower digit | |
int hl = now.hour() % 10; | |
lc.setColumn(0,1,myBinaryDisp[hl]); | |
// update minutes | |
// upper digit | |
int mh = now.minute() / 10; | |
lc.setColumn(0,3,myBinaryDisp[mh]); | |
//lower digit | |
int ml = now.minute() % 10; | |
lc.setColumn(0,4,myBinaryDisp[ml]); | |
// update seconds | |
// upper digit | |
int sh = now.second() / 10; | |
lc.setColumn(0,6,myBinaryDisp[sh]); | |
//lower digit | |
int sl = now.second() % 10; | |
lc.setColumn(0,7,myBinaryDisp[sl]); | |
} | |
// ISR routine | |
void onesecond() { | |
is_second = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment