搜索代码

Build a Seven-Segment LED Clock with Arduino

Build a Seven-Segment LED Clock with Arduino

This code is for video instruction on how to build a seven-segment LED clock using a DS3231 real-time clock and an Arduino. The RoboJax library makes it very easy to build the clock in a few lines.

223-Seven-segment LED clock with Arduino and DS3231
语言: C++
/*
 * Seven Segment LED Clock with Arduino and DS3231
 * with Robojax Library
 * 
 * Written by Ahmad Shamshiri 
 * on July 26, 2018 at 21:29 in Ajax, Ontario, Canada

Watch video instructions for this code: https://youtu.be/qB0drI56zGE
Watch video instructions for DS3231: https://youtu.be/7hBtXdoaAOY
Get this code and other Arduino codes from Robojax.com
If you found this tutorial helpful, please support me so I can continue creating 
content like this. 
or make a donation using PayPal http://robojax.com/L/?id=64

 * 
  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;

#include <Robojax_SevenSegmentClock.h>
const int digits[]={9,10,11,12};// define digits pins
const int displayPins[] = {2,3,4,5,6,7,8}; // define segment pins
const int colonPin = 13;// colon pin
const int type =1;//1 common Anode, 2 for commond cathode
Robojax_SevenSegmentClock clk(displayPins,digits,colonPin,type);

int blinkTime=0;// do not change. Used internally
int blinkStatus=0;// do not change. Used internally

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

  // Initialize DS3231
  Serial.println("Initialize DS3231");
  clock.begin();//for DS3231 
  
  clk.begin();//for Robojax_SevenSegmentClock
  Serial.println("Robojax Seven Segment Display Clock");
  Serial.println("V 1.0 July 28, 2019"); 
  
  // Robojax Seven Segment Clock for Arduino
  // uncomment the line below only ONCE to update the time. Then comment it back
  //clock.setDateTime(__DATE__, __TIME__);
}// setup ends here


void loop() {
  // Robojax Seven Segment LED Clock with Arduino
   dt = clock.getDateTime();
//  Serial.print(dt.hour);   Serial.print(":");
//  Serial.print(dt.minute); Serial.print(":");
//  Serial.print(dt.second); Serial.println("");   
  clk.displayTime(dt.hour,dt.minute);
  

  delay(1);

}// loop ends here

资源与参考

尚无可用资源。

文件📁

Arduino 库(zip 格式)