Arduino to-the-minute word clock OLED Display
An Arduino based word clock that tells the day of the week, the month, day and year and the time to the minute in words.
Components and supplies
1
Jumper wires (generic)
1
0.91 Inch 128x32 IIC I2C Blue OLED LCD Display DIY Oled Module SSD1306 Driver IC DC 3.3V 5V For Arduino PIC
1
Arduino Nano R3
1
Real Time Clock (RTC)
Project description
Code
tothe minute word clock
arduino
1// Date and time functions using a DS1307 RTC connected via I2C and Wire lib 2#include <Wire.h> 3#include "RTClib.h" 4#include <SPI.h> 5#include <Adafruit_GFX.h> 6#include <Adafruit_SSD1306.h> 7#define OLED_RESET 4 8Adafruit_SSD1306 display(OLED_RESET); 9#if (SSD1306_LCDHEIGHT != 32) 10#error("Height incorrect, please fix Adafruit_SSD1306.h!"); 11#endif 12#define Today 13RTC_DS1307 rtc; 14 15char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 16 17void setup () { 18 while (!Serial); // for Leonardo/Micro/Zero 19 20 Serial.begin(9600); 21 22 23 if (! rtc.begin()) { 24 25 while (1); 26 } 27 28 if (! rtc.isrunning()) { 29 30 // following line sets the RTC to the date & time this sketch was compiled 31 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 32 // This line sets the RTC with an explicit date & time, for example to set 33 // January 21, 2014 at 3am you would call: 34 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 35 } 36 Wire.begin(); 37 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 38 // init done 39 //Clear the buffer. 40 display.clearDisplay(); 41 text(); 42} 43void text(void) { 44 display.setTextSize(1); 45 display.setTextColor(WHITE); 46} 47void Display () { 48 display.clearDisplay(); 49 DateTime now = rtc.now(); 50 51 //set day of week 52 display.setCursor(0,0); 53 display.print("Today is "); 54 55display.print(daysOfTheWeek[now.dayOfTheWeek()]); 56 57 58//set date 59 display.setCursor(0,12); 60 int mo=now.month(); 61 62 if ((mo>0)&&(mo<2)){ 63 display.print("January "); 64 } 65 if ((mo>1)&&(mo<3)){ 66 display.print("February "); 67 } 68 if ((mo>2)&&(mo<4)){ 69 display.print("March "); 70 } 71 if ((mo>3)&&(mo<5)){ 72 display.print("April "); 73 } 74 if ((mo>4)&&(mo<6)){ 75 display.print("May "); 76 } 77 if ((mo>5)&&(mo<7)){ 78 display.print("June "); 79 } 80 if ((mo>6)&&(mo<8)){ 81 display.print("July "); 82 } 83 if ((mo>7)&&(mo<9)){ 84 display.print("August "); 85 } 86 if ((mo>8)&&(mo<10)){ 87 display.print("September "); 88 } 89 if ((mo>9)&&(mo<11)){ 90 display.print("October "); 91 } 92 if ((mo>10)&&(mo<12)){ 93 display.print("November "); 94 } 95 if ((mo>11)&&(mo<13)){ 96 display.print("December "); 97 } 98 99 100 display.print (now.day(), DEC); 101 102 103 display.print(", "); 104 105 display.print (now.year(), DEC); 106 107 //set hour 108 display.setCursor(0,24); 109 int hr=now.hour(); 110 if (hr>12){ 111 hr=hr-12; 112 } 113 if ((hr>0)&&(hr<2)){ 114 display.print("One "); 115 } 116 if ((hr>1)&&(hr<3)){ 117 display.print("Two "); 118 } 119 if ((hr>2)&&(hr<4)){ 120 display.print("Three "); 121 } 122 if ((hr>3)&&(hr<5)){ 123 display.print("Four "); 124 } 125 if ((hr>4)&&(hr<6)){ 126 display.print("Five "); 127 } 128 if ((hr>5)&&(hr<7)){ 129 display.print("Six "); 130 } 131 if ((hr>6)&&(hr<8)){ 132 display.print("Seven "); 133 } 134 if ((hr>7)&&(hr<9)){ 135 display.print("Eight "); 136 } 137 if ((hr>8)&&(hr<10)){ 138 display.print("Nine "); 139 } 140 if ((hr>9)&&(hr<11)){ 141 display.print("Ten "); 142 } 143 if ((hr>10)&&(hr<12)){ 144 display.print("Eleven "); 145 146 147 } 148 if ((hr>11)&&(hr<13)){ 149 display.print("Twelve "); 150 } 151 152 153 // set minute 154 155 int m=now.minute(); 156 157 if ((m>0)&&(m<2)){ 158 display.print("O-One"); 159 } 160 if ((m>1)&&(m<3)){ 161 display.print("O-Two"); 162 } 163 164 if ((m>2)&&(m<4)){ 165 display.print("O-Three"); 166 } 167 if ((m>3)&&(m<5)){ 168 display.print("O-Four"); 169 } 170 if ((m>4)&&(m<6)){ 171 display.print("O-Five"); 172 } 173 174 if ((m>5)&&(m<7)){ 175 display.print("O-Six"); 176 } 177 178 if ((m>6)&&(m<8)){ 179 display.print("O-Seven"); 180 } 181 if ((m>7)&&(m<9)){ 182 display.print("O-Eight"); 183 } 184 185 if ((m>8)&&(m<10)){ 186 display.print("O-Nine"); 187 } 188 189 //teens 190 if ((m>9)&&(m<11)){ 191 display.print("Ten"); 192 } 193 if ((m>10)&&(m<12)){ 194 display.print("Eleven"); 195 } 196 197 if ((m>11)&&(m<13)){ 198 display.print("Twelve"); 199 } 200 201 if ((m>12)&&(m<14)){ 202 display.print("Thirteen"); 203 } 204 if ((m>13)&&(m<15)){ 205 display.print("Fourteen"); 206 } 207 208 if ((m>14)&&(m<16)){ 209 Serial.print("Fifteen"); 210 } 211 if ((m>15)&&(m<17)){ 212 display.print("Sixteen"); 213 } 214 if ((m>16)&&(m<18)){ 215 display.print("Seventeen"); 216 } 217 218 if ((m>17)&&(m<19)){ 219 display.print("Eighteen"); 220 } 221 222 if ((m>18)&&(m<20)){ 223 display.print("Ninteen"); 224 } 225 226 //twenty 227 if ((m>19)&&(m<21)){ 228 display.print("Twenty"); 229 } 230 231 if ((m>20)&&(m<22)){ 232 Serial.print("Twenty-One"); 233 } 234 if ((m>21)&&(m<23)){ 235 display.print("Twenty-Two"); 236 } 237 if ((m>22)&&(m<24)){ 238 display.print("Twenty-Three"); 239 } 240 241 if ((m>23)&&(m<25)){ 242 Serial.print("Twenty-Four"); 243 } 244 245 if ((m>24)&&(m<26)){ 246 display.print("Twenty-Five"); 247 } 248 if ((m>25)&&(m<27)){ 249 display.print("Twenty-Six"); 250 } 251 if ((m>26)&&(m<28)){ 252 display.print("Twenty-Seven"); 253 } 254 255 if ((m>27)&&(m<29)){ 256 Serial.print("Twenty-Eight"); 257 } 258 259 if ((m>28)&&(m<30)){ 260 display.print("Twenty-Nine"); 261 } 262 263 // thirty 264 if ((m>29)&&(m<31)){ 265 display.print("Thirty"); 266 } 267 268 if ((m>30)&&(m<32)){ 269 display.print("Thirty-One"); 270 } 271 if ((m>31)&&(m<33)){ 272 display.print("Thirty-Two"); 273 } 274 if ((m>32)&&(m<34)){ 275 display.print("Thirty-Three"); 276 277 } 278 279 if ((m>33)&&(m<35)){ 280 display.print("Thirty-Four"); 281 282 } 283 284 if ((m>34)&&(m<36)){ 285 display.print("Thirty-Five"); 286 287 } 288 if ((m>35)&&(m<37)){ 289 display.print("Thirty-Six"); 290 291 } 292 if ((m>36)&&(m<38)){ 293 display.print("Thirty-Seven"); 294 295 } 296 297 if ((m>37)&&(m<39)){ 298 display.print("Thirty-Eight"); 299 } 300 301 if ((m>38)&&(m<40)){ 302 display.print("Thirty-Nine"); 303 } 304 305 //forty 306 if ((m>39)&&(m<41)){ 307 display.print("Forty"); 308 } 309 310 if ((m>40)&&(m<42)){ 311 display.print("Forty-One"); 312 } 313 if ((m>41)&&(m<43)){ 314 display.print("Forty-Two"); 315 } 316 if ((m>42)&&(m<44)){ 317 display.print("Forty-Three"); 318 } 319 320 if ((m>43)&&(m<45)){ 321 display.print("Forty-Four"); 322 } 323 324 if ((m>44)&&(m<46)){ 325 display.print("Forty-Five"); 326 } 327 if ((m>45)&&(m<47)){ 328 display.print("Forty-Six"); 329 } 330 if ((m>46)&&(m<48)){ 331 display.print("Forty-Seven"); 332 } 333 334 if ((m>47)&&(m<49)){ 335 display.print("Forty-Eight"); 336 } 337 338 if ((m>48)&&(m<50)){ 339 display.print("Forty-Nine"); 340 } 341 342 //fifty 343 if ((m>49)&&(m<51)){ 344 display.print("Fifty"); 345 } 346 347 if ((m>50)&&(m<52)){ 348 display.print("Fifty-One"); 349 } 350 if ((m>51)&&(m<53)){ 351 display.print("Fifty-Two"); 352 } 353 if ((m>52)&&(m<54)){ 354 display.print("Fifty-Three"); 355 } 356 357 if ((m>53)&&(m<55)){ 358 display.print("Fifty-Four"); 359 } 360 361 if ((m>54)&&(m<56)){ 362 Serial.print("Fifty-Five"); 363 } 364 if ((m>55)&&(m<57)){ 365 display.print("Fifty-Six"); 366 } 367 if ((m>56)&&(m<58)){ 368 display.print("Fifty-Seven"); 369 } 370 371 if ((m>57)&&(m<59)){ 372 display.print("Fifty-Eight"); 373 } 374 375 if ((m>58)){ 376 display.print("Fifty-Nine"); 377 } 378 379 if (m<1){ 380 display.print("O'Clock"); 381 } 382 383 384 display.print(" "); 385 386 int tm=now.hour(); 387 if (tm<13){ 388 display.print("AM"); 389 } 390 391 392 393 if (tm>12){ 394 display.print("PM"); 395 } 396 397 display.display(); 398} 399void loop() 400 401 402 { 403 Display(); 404 delay(0); 405 } 406 407
tothe minute word clock
arduino
1// Date and time functions using a DS1307 RTC connected via I2C and Wire lib 2#include <Wire.h> 3#include "RTClib.h" 4#include <SPI.h> 5#include <Adafruit_GFX.h> 6#include <Adafruit_SSD1306.h> 7#define OLED_RESET 4 8Adafruit_SSD1306 display(OLED_RESET); 9#if (SSD1306_LCDHEIGHT != 32) 10#error("Height incorrect, please fix Adafruit_SSD1306.h!"); 11#endif 12#define Today 13RTC_DS1307 rtc; 14 15char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 16 17void setup () { 18 while (!Serial); // for Leonardo/Micro/Zero 19 20 Serial.begin(9600); 21 22 23 if (! rtc.begin()) { 24 25 while (1); 26 } 27 28 if (! rtc.isrunning()) { 29 30 // following line sets the RTC to the date & time this sketch was compiled 31 rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 32 // This line sets the RTC with an explicit date & time, for example to set 33 // January 21, 2014 at 3am you would call: 34 // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 35 } 36 Wire.begin(); 37 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 38 // init done 39 //Clear the buffer. 40 display.clearDisplay(); 41 text(); 42} 43void text(void) { 44 display.setTextSize(1); 45 display.setTextColor(WHITE); 46} 47void Display () { 48 display.clearDisplay(); 49 DateTime now = rtc.now(); 50 51 //set day of week 52 display.setCursor(0,0); 53 display.print("Today is "); 54 55display.print(daysOfTheWeek[now.dayOfTheWeek()]); 56 57 58//set date 59 display.setCursor(0,12); 60 int mo=now.month(); 61 62 if ((mo>0)&&(mo<2)){ 63 display.print("January "); 64 } 65 if ((mo>1)&&(mo<3)){ 66 display.print("February "); 67 } 68 if ((mo>2)&&(mo<4)){ 69 display.print("March "); 70 } 71 if ((mo>3)&&(mo<5)){ 72 display.print("April "); 73 } 74 if ((mo>4)&&(mo<6)){ 75 display.print("May "); 76 } 77 if ((mo>5)&&(mo<7)){ 78 display.print("June "); 79 } 80 if ((mo>6)&&(mo<8)){ 81 display.print("July "); 82 } 83 if ((mo>7)&&(mo<9)){ 84 display.print("August "); 85 } 86 if ((mo>8)&&(mo<10)){ 87 display.print("September "); 88 } 89 if ((mo>9)&&(mo<11)){ 90 display.print("October "); 91 } 92 if ((mo>10)&&(mo<12)){ 93 display.print("November "); 94 } 95 if ((mo>11)&&(mo<13)){ 96 display.print("December "); 97 } 98 99 100 display.print (now.day(), DEC); 101 102 103 display.print(", "); 104 105 display.print (now.year(), DEC); 106 107 //set hour 108 display.setCursor(0,24); 109 int hr=now.hour(); 110 if (hr>12){ 111 hr=hr-12; 112 } 113 if ((hr>0)&&(hr<2)){ 114 display.print("One "); 115 } 116 if ((hr>1)&&(hr<3)){ 117 display.print("Two "); 118 } 119 if ((hr>2)&&(hr<4)){ 120 display.print("Three "); 121 } 122 if ((hr>3)&&(hr<5)){ 123 display.print("Four "); 124 } 125 if ((hr>4)&&(hr<6)){ 126 display.print("Five "); 127 } 128 if ((hr>5)&&(hr<7)){ 129 display.print("Six "); 130 } 131 if ((hr>6)&&(hr<8)){ 132 display.print("Seven "); 133 } 134 if ((hr>7)&&(hr<9)){ 135 display.print("Eight "); 136 } 137 if ((hr>8)&&(hr<10)){ 138 display.print("Nine "); 139 } 140 if ((hr>9)&&(hr<11)){ 141 display.print("Ten "); 142 } 143 if ((hr>10)&&(hr<12)){ 144 display.print("Eleven "); 145 146 147 } 148 if ((hr>11)&&(hr<13)){ 149 display.print("Twelve "); 150 } 151 152 153 // set minute 154 155 int m=now.minute(); 156 157 if ((m>0)&&(m<2)){ 158 display.print("O-One"); 159 } 160 if ((m>1)&&(m<3)){ 161 display.print("O-Two"); 162 } 163 164 if ((m>2)&&(m<4)){ 165 display.print("O-Three"); 166 } 167 if ((m>3)&&(m<5)){ 168 display.print("O-Four"); 169 } 170 if ((m>4)&&(m<6)){ 171 display.print("O-Five"); 172 } 173 174 if ((m>5)&&(m<7)){ 175 display.print("O-Six"); 176 } 177 178 if ((m>6)&&(m<8)){ 179 display.print("O-Seven"); 180 } 181 if ((m>7)&&(m<9)){ 182 display.print("O-Eight"); 183 } 184 185 if ((m>8)&&(m<10)){ 186 display.print("O-Nine"); 187 } 188 189 //teens 190 if ((m>9)&&(m<11)){ 191 display.print("Ten"); 192 } 193 if ((m>10)&&(m<12)){ 194 display.print("Eleven"); 195 } 196 197 if ((m>11)&&(m<13)){ 198 display.print("Twelve"); 199 } 200 201 if ((m>12)&&(m<14)){ 202 display.print("Thirteen"); 203 } 204 if ((m>13)&&(m<15)){ 205 display.print("Fourteen"); 206 } 207 208 if ((m>14)&&(m<16)){ 209 Serial.print("Fifteen"); 210 } 211 if ((m>15)&&(m<17)){ 212 display.print("Sixteen"); 213 } 214 if ((m>16)&&(m<18)){ 215 display.print("Seventeen"); 216 } 217 218 if ((m>17)&&(m<19)){ 219 display.print("Eighteen"); 220 } 221 222 if ((m>18)&&(m<20)){ 223 display.print("Ninteen"); 224 } 225 226 //twenty 227 if ((m>19)&&(m<21)){ 228 display.print("Twenty"); 229 } 230 231 if ((m>20)&&(m<22)){ 232 Serial.print("Twenty-One"); 233 } 234 if ((m>21)&&(m<23)){ 235 display.print("Twenty-Two"); 236 } 237 if ((m>22)&&(m<24)){ 238 display.print("Twenty-Three"); 239 } 240 241 if ((m>23)&&(m<25)){ 242 Serial.print("Twenty-Four"); 243 } 244 245 if ((m>24)&&(m<26)){ 246 display.print("Twenty-Five"); 247 } 248 if ((m>25)&&(m<27)){ 249 display.print("Twenty-Six"); 250 } 251 if ((m>26)&&(m<28)){ 252 display.print("Twenty-Seven"); 253 } 254 255 if ((m>27)&&(m<29)){ 256 Serial.print("Twenty-Eight"); 257 } 258 259 if ((m>28)&&(m<30)){ 260 display.print("Twenty-Nine"); 261 } 262 263 // thirty 264 if ((m>29)&&(m<31)){ 265 display.print("Thirty"); 266 } 267 268 if ((m>30)&&(m<32)){ 269 display.print("Thirty-One"); 270 } 271 if ((m>31)&&(m<33)){ 272 display.print("Thirty-Two"); 273 } 274 if ((m>32)&&(m<34)){ 275 display.print("Thirty-Three"); 276 277 } 278 279 if ((m>33)&&(m<35)){ 280 display.print("Thirty-Four"); 281 282 } 283 284 if ((m>34)&&(m<36)){ 285 display.print("Thirty-Five"); 286 287 } 288 if ((m>35)&&(m<37)){ 289 display.print("Thirty-Six"); 290 291 } 292 if ((m>36)&&(m<38)){ 293 display.print("Thirty-Seven"); 294 295 } 296 297 if ((m>37)&&(m<39)){ 298 display.print("Thirty-Eight"); 299 } 300 301 if ((m>38)&&(m<40)){ 302 display.print("Thirty-Nine"); 303 } 304 305 //forty 306 if ((m>39)&&(m<41)){ 307 display.print("Forty"); 308 } 309 310 if ((m>40)&&(m<42)){ 311 display.print("Forty-One"); 312 } 313 if ((m>41)&&(m<43)){ 314 display.print("Forty-Two"); 315 } 316 if ((m>42)&&(m<44)){ 317 display.print("Forty-Three"); 318 } 319 320 if ((m>43)&&(m<45)){ 321 display.print("Forty-Four"); 322 } 323 324 if ((m>44)&&(m<46)){ 325 display.print("Forty-Five"); 326 } 327 if ((m>45)&&(m<47)){ 328 display.print("Forty-Six"); 329 } 330 if ((m>46)&&(m<48)){ 331 display.print("Forty-Seven"); 332 } 333 334 if ((m>47)&&(m<49)){ 335 display.print("Forty-Eight"); 336 } 337 338 if ((m>48)&&(m<50)){ 339 display.print("Forty-Nine"); 340 } 341 342 //fifty 343 if ((m>49)&&(m<51)){ 344 display.print("Fifty"); 345 } 346 347 if ((m>50)&&(m<52)){ 348 display.print("Fifty-One"); 349 } 350 if ((m>51)&&(m<53)){ 351 display.print("Fifty-Two"); 352 } 353 if ((m>52)&&(m<54)){ 354 display.print("Fifty-Three"); 355 } 356 357 if ((m>53)&&(m<55)){ 358 display.print("Fifty-Four"); 359 } 360 361 if ((m>54)&&(m<56)){ 362 Serial.print("Fifty-Five"); 363 } 364 if ((m>55)&&(m<57)){ 365 display.print("Fifty-Six"); 366 } 367 if ((m>56)&&(m<58)){ 368 display.print("Fifty-Seven"); 369 } 370 371 if ((m>57)&&(m<59)){ 372 display.print("Fifty-Eight"); 373 } 374 375 if ((m>58)){ 376 display.print("Fifty-Nine"); 377 } 378 379 if (m<1){ 380 display.print("O'Clock"); 381 } 382 383 384 display.print(" "); 385 386 int tm=now.hour(); 387 if (tm<13){ 388 display.print("AM"); 389 } 390 391 392 393 if (tm>12){ 394 display.print("PM"); 395 } 396 397 display.display(); 398} 399void loop() 400 401 402 { 403 Display(); 404 delay(0); 405 } 406 407
Downloadable files
ttmwordclcok
ttmwordclcok
Comments
Only logged in users can leave comments