Previously, we talked about 7 Segment 4 Digit TM1637 Display. In This Guide We Will Be Making a Digital Clock With Arduino 7 Segment 4 Digit TM1637 Display Unit. It is important to read the linked guide. We are including circuit diagram and code for completing the project. Total cost will be of Arduino, 7 Segment 4 Digit TM1637 display (around $3), one DS3231 Real Time Clock Module ($1.5) and three push buttons (few cents), one breadboard (normally we have), few jumpers. It is costly in terms of electronics.
Making a Digital Clock : Arduino 7 Segment 4 Digit TM1637 and DS3231 RTC Module
In the above linked guide we told you that for real time clock (RTC), we need another chip. That DS3231 real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar. The clock can operate in either the 24-hour or 12-hour format with AM/PM indicator, but the library only supports the 24-hour mode. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. We need the below library for TM1637 :
1 | http://www.seeedstudio.com/wiki/File:DigitalTube.zip |
You can watch the video of what exactly going to happen :
---
1 | https://www.youtube.com/watch?v=JyIqXafq9eg&feature=youtu.be |
Making a Digital Clock With Arduino 7 Segment 4 Digit TM1637
That video provided the non-English language website who essentially provided the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #include <Wire.h> #include "TM1637.h" #define CLK 6 #define DIO 7 #define brightness 6 #define keyHor 5 #define keyMin 4 #define keyPL 3 TM1637 tm1637(CLK,DIO); #define DS3231_I2C_ADDRESS 0x68 volatile boolean flag; byte decToBcd(byte val){ return ( (val/10*16) + (val%10) ); } byte bcdToDec(byte val){ return ( (val/16*10) + (val%16) ); } void setDateDs3231(byte second, byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); Wire.write(decToBcd(second)); Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(dayOfWeek)); Wire.write(decToBcd(dayOfMonth)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.endTransmission(); } void getDateDs3231(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) { Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setINT(){ Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0x0E); Wire.write(0x0); Wire.endTransmission(); } void blink() { digitalWrite(13, !digitalRead(13)); flag = !flag; tm1637.point(flag); } void setup() { // Serial.begin(9600); Wire.begin(); pinMode(13, OUTPUT); pinMode(keyHor, INPUT_PULLUP); pinMode(keyMin, INPUT_PULLUP); pinMode(keyPL, INPUT_PULLUP); tm1637.init(); tm1637.set(brightness); setINT(); attachInterrupt(0, blink, CHANGE); } void loop(){ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs3231(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); int8_t TimeDisp[4]; TimeDisp[0] = hour / 10; TimeDisp[1] = hour % 10; TimeDisp[2] = minute / 10; TimeDisp[3] = minute % 10; if (!digitalRead(keyHor) && !digitalRead(keyPL)){ second = 0; hour++; if (hour > 23) hour = 0; setDateDs3231(second, minute, hour, dayOfWeek, dayOfMonth, month, year); delay(200); } if (!digitalRead(keyMin) && !digitalRead(keyPL)){ // минуты second = 0; minute++; if (minute > 59) minute = 0; setDateDs3231(second, minute, hour, dayOfWeek, dayOfMonth, month, year); delay(200); } tm1637.display(TimeDisp); } |
Here is the gist of the above code in unmodified form.
Tagged With TM1637 , tm1637 clock , arduino tm1637 clock , tm1637 arduino clock , picbasic write to tm1637 , tm1637 with rtc , arduino 7 segment clock , arduino seven segment clock , arduino 7 segment tm1637 , DS3231 on 4 digit display