Components and supplies
Brake rotor
Jumper wires (generic)
carbon fiber
Arduino UNO
4 digit 7 segment display
RTC Module
Breadboard (generic)
Tools and machines
Hot glue gun (generic)
Apps and platforms
Arduino IDE
Project description
Code
Code
arduino
You must download the RTClib.h library from this link : https://github.com/adafruit/RTClib
1#include <Wire.h> 2#include <RTClib.h> 3 4//DP G F E D C B A 5const 6 byte segmentMap[10] = { 7 B00111111, //0 8 B00000110, //1 9 B01011011, 10 //2 11 B01001111, //3 12 B01100110, //4 13 B01101101, //5 14 B01111101, 15 //6 16 B00000111, //7 17 B01111111, //8 18 B01100111 //9 19}; 20 21RTC_DS3231 22 rtc; 23 24const int segmentPins[8] = {2,3,4,5,6,7,8,9}; // A B C D E F G DP 25const 26 int digitPins[4] = {10,11,12,13}; //DIG1 DIG2 DIG3 DIG4 27 28void setup() 29 { 30 31 // Set the segment pins as outputs 32 for (int i=0; i<8; i++) { 33 34 pinMode(segmentPins[i], OUTPUT); 35 digitalWrite(segmentPins[i], LOW); 36 37 } 38 39 // Set the digit pins as outputs 40 for (int i=0; i<4; i++) { 41 42 pinMode(digitPins[i], OUTPUT); 43 digitalWrite(digitPins[i], HIGH); 44 45 } 46 47 if (! rtc.begin()) { 48 while (1); 49 } 50 51 if (rtc.lostPower()) 52 { 53 // following line sets the RTC to the date & time this sketch was compiled 54 55 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 56 // This line sets the 57 RTC with an explicit date & time, for example to set 58 // January 21, 2014 59 at 3am you would call: 60 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 61 62 } 63 64} 65 66void loop() { 67 68 int digits[4]; 69 int hour; 70 71 int minute; 72 73 DateTime now = rtc.now(); 74 75 // Convert 24 76 -> 12 hour 77 if (now.hour() > 12) { 78 hour = now.hour() - 12; 79 } 80 else { 81 hour = now.hour(); 82 } 83 minute = now.minute(); 84 85 86 // Figure out individual digits 87 digits[0] = hour / 10; 88 digits[1] 89 = hour % 10; 90 digits[2] = minute / 10; 91 digits[3] = minute % 10; 92 93 94 for (int i=0; i<=3; i++) { 95 displayNumber(digits[i], i, 5); 96 } 97 98 99} 100 101void displayNumber(int number, int digit, int duration) { 102 103 if 104 ((number >=0 && number <=9) && (digit >= 0 && digit <=3)) { 105 // Turn on appropriate 106 digit 107 digitalWrite(digitPins[digit], LOW); 108 // Turn on appropriate 109 segments 110 for (int seg=0; seg<8; seg++) { 111 digitalWrite(segmentPins[seg], 112 bitRead(segmentMap[number], seg)); 113 } 114 delay(duration); 115 // 116 Turn off digit 117 digitalWrite(digitPins[digit], HIGH); 118 } 119 120} 121
Code
arduino
You must download the RTClib.h library from this link : https://github.com/adafruit/RTClib
1#include <Wire.h> 2#include <RTClib.h> 3 4//DP G F E D C B A 5const byte segmentMap[10] = { 6 B00111111, //0 7 B00000110, //1 8 B01011011, //2 9 B01001111, //3 10 B01100110, //4 11 B01101101, //5 12 B01111101, //6 13 B00000111, //7 14 B01111111, //8 15 B01100111 //9 16}; 17 18RTC_DS3231 rtc; 19 20const int segmentPins[8] = {2,3,4,5,6,7,8,9}; // A B C D E F G DP 21const int digitPins[4] = {10,11,12,13}; //DIG1 DIG2 DIG3 DIG4 22 23void setup() { 24 25 // Set the segment pins as outputs 26 for (int i=0; i<8; i++) { 27 pinMode(segmentPins[i], OUTPUT); 28 digitalWrite(segmentPins[i], LOW); 29 } 30 31 // Set the digit pins as outputs 32 for (int i=0; i<4; i++) { 33 pinMode(digitPins[i], OUTPUT); 34 digitalWrite(digitPins[i], HIGH); 35 } 36 37 if (! rtc.begin()) { 38 while (1); 39 } 40 41 if (rtc.lostPower()) { 42 // following line sets the RTC to the date & time this sketch was compiled 43 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 44 // This line sets the RTC with an explicit date & time, for example to set 45 // January 21, 2014 at 3am you would call: 46 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 47 } 48 49} 50 51void loop() { 52 53 int digits[4]; 54 int hour; 55 int minute; 56 57 DateTime now = rtc.now(); 58 59 // Convert 24 -> 12 hour 60 if (now.hour() > 12) { 61 hour = now.hour() - 12; 62 } else { 63 hour = now.hour(); 64 } 65 minute = now.minute(); 66 67 // Figure out individual digits 68 digits[0] = hour / 10; 69 digits[1] = hour % 10; 70 digits[2] = minute / 10; 71 digits[3] = minute % 10; 72 73 for (int i=0; i<=3; i++) { 74 displayNumber(digits[i], i, 5); 75 } 76 77} 78 79void displayNumber(int number, int digit, int duration) { 80 81 if ((number >=0 && number <=9) && (digit >= 0 && digit <=3)) { 82 // Turn on appropriate digit 83 digitalWrite(digitPins[digit], LOW); 84 // Turn on appropriate segments 85 for (int seg=0; seg<8; seg++) { 86 digitalWrite(segmentPins[seg], bitRead(segmentMap[number], seg)); 87 } 88 delay(duration); 89 // Turn off digit 90 digitalWrite(digitPins[digit], HIGH); 91 } 92 93} 94
Downloadable files
the schematic
the schematic
Comments
Only logged in users can leave comments
tylerpeppy
0 Followers
•0 Projects
Table of contents
Intro
1
0