Components and supplies
Jumper wires (generic)
DS3231MPMB1 Peripheral Module
USB-A to B Cable
Arduino UNO
oled screen
Project description
Code
untitled
c_cpp
1//arduino clock by blogduino 30/09/2022 2 3 4 5#include <SPI.h> 6#include <Wire.h> 7#include <Adafruit_GFX.h> 8#include <Adafruit_SH110X.h> 9//fonts https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts#step-2 10#include <Fonts/FreeSerif9pt7b.h> 11#include <RTClib.h> 12 13#define i2c_Address 0x3c 14#define SCREEN_WIDTH 128 15#define SCREEN_HEIGHT 64 16#define OLED_RESET -1 17Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 18RTC_DS3231 rtc; 19 20 21int day; 22int month; 23int year; 24int temperature; 25String time; 26 27void setup(void) { 28 // put your setup code here, to run once: 29Serial.begin(115200); 30 delay(250); 31 display.begin(i2c_Address, true); 32 // SETUP RTC MODULE 33 if (! rtc.begin()) { 34 Serial.println("Couldn't find RTC"); 35 Serial.flush(); 36 while (true); 37 } 38 39 // automatically sets the RTC to the date & time on PC this sketch was compiled 40 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 41 time.reserve(1); // to avoid fragmenting memory when using String 42 43 44} 45 46void loop() { 47 // put your main code here, to run repeatedly: 48 49 50 DateTime now = rtc.now(); 51 52 time = ""; 53 time += now.hour(); 54 time += ':'; 55 time += now.minute(); 56 time += ':'; 57 time += now.second(); 58 59 day = now.day(); 60 month = now.month(); 61 year = now.year(); 62 temperature = rtc.getTemperature(); 63 64if(millis()%1000==0){ 65 display.clearDisplay(); 66 display.setTextSize(2); 67 //display.setFont(&FreeSerif9pt7b); 68 display.setTextColor(SH110X_WHITE); 69 display.setCursor(20, 5); 70 display.println(time); 71 72 73 74 //Original Font 75 display.setFont(); 76 display.setCursor(45, 25); 77 display.println(temperature); 78 display.setCursor(70, 25); 79 display.println('c'); 80 display.setTextSize(2); 81 display.setCursor(8, 45); 82 display.println(day); 83 display.setCursor(51,45); 84 display.println(month); 85 display.setCursor(79,45); 86 display.println(year); 87 display.setTextSize(3); 88 display.setCursor(34,40); 89 display.println('/'); 90 display.setCursor(62,40); 91 display.println('/'); 92 93 display.display(); 94 95 } 96} 97
untitled
c_cpp
1//arduino clock by blogduino 30/09/2022 2 3 4 5#include <SPI.h> 6#include 7 <Wire.h> 8#include <Adafruit_GFX.h> 9#include <Adafruit_SH110X.h> 10//fonts 11 https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts#step-2 12#include 13 <Fonts/FreeSerif9pt7b.h> 14#include <RTClib.h> 15 16#define i2c_Address 0x3c 17 18#define SCREEN_WIDTH 128 19#define SCREEN_HEIGHT 64 20#define OLED_RESET 21 -1 22Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, 23 &Wire, OLED_RESET); 24RTC_DS3231 rtc; 25 26 27int day; 28int month; 29int 30 year; 31int temperature; 32String time; 33 34void setup(void) { 35 // put 36 your setup code here, to run once: 37Serial.begin(115200); 38 delay(250); 39 40 display.begin(i2c_Address, true); 41 // SETUP RTC MODULE 42 if (! rtc.begin()) 43 { 44 Serial.println("Couldn't find RTC"); 45 Serial.flush(); 46 while 47 (true); 48 } 49 50 // automatically sets the RTC to the date & time on PC this 51 sketch was compiled 52 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 53 time.reserve(1); 54 // to avoid fragmenting memory when using String 55 56 57} 58 59void loop() 60 { 61 // put your main code here, to run repeatedly: 62 63 64 DateTime now = 65 rtc.now(); 66 67 time = ""; 68 time += now.hour(); 69 time += ':'; 70 71 time += now.minute(); 72 time += ':'; 73 time += now.second(); 74 75 day 76 = now.day(); 77 month = now.month(); 78 year = now.year(); 79 temperature = 80 rtc.getTemperature(); 81 82if(millis()%1000==0){ 83 display.clearDisplay(); 84 85 display.setTextSize(2); 86 //display.setFont(&FreeSerif9pt7b); 87 display.setTextColor(SH110X_WHITE); 88 89 display.setCursor(20, 5); 90 display.println(time); 91 92 93 94 95 //Original Font 96 display.setFont(); 97 display.setCursor(45, 98 25); 99 display.println(temperature); 100 display.setCursor(70, 25); 101 102 display.println('c'); 103 display.setTextSize(2); 104 display.setCursor(8, 105 45); 106 display.println(day); 107 display.setCursor(51,45); 108 display.println(month); 109 110 display.setCursor(79,45); 111 display.println(year); 112 display.setTextSize(3); 113 114 display.setCursor(34,40); 115 display.println('/'); 116 display.setCursor(62,40); 117 118 display.println('/'); 119 120 display.display(); 121 122 } 123} 124
Downloadable files
img_20220930_201944_nYMH3DDYDL.jpg
img_20220930_201944_nYMH3DDYDL.jpg
Comments
Only logged in users can leave comments
mekong07
0 Followers
•0 Projects
0