Components and supplies
Breadboard (generic)
0.91 inch OLED 128 X 32 display
Pushbutton switch 12mm
Jumper wires (generic)
Arduino Nano R3
Project description
Code
simple word clock
arduino
1#include <Wire.h> 2#include <Time.h> 3#include <SPI.h> 4#include <TimeLib.h> 5 6#include <Adafruit_GFX.h> 7#include <Adafruit_SSD1306.h> 8#define OLED_RESET 4 9Adafruit_SSD1306 display(OLED_RESET); 10#if (SSD1306_LCDHEIGHT != 32) 11#error("Height incorrect, please fix Adafruit_SSD1306.h!"); 12#endif 13byte mm1, mm5, h, m, s; 14byte ultM = 10, ultH = 10; 15byte hPin = 3, mPin = 2; 16boolean ajustaH = true, ajustaM = true; 17 18 19void setup() { 20 21 Serial.begin(9600); 22 pinMode(hPin, INPUT_PULLUP); 23 pinMode(mPin, INPUT_PULLUP); 24 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 25 // init done 26 //Clear the buffer. 27 display.clearDisplay(); 28 text(); 29 30} 31 32 33 34void text(void) { 35 display.setTextSize(1); 36 display.setTextColor(WHITE); 37 38 39 40 41} 42 43void Display() { 44 45 // Setup of Hours & Minutes 46 ajustaH = digitalRead(hPin); 47 ajustaM = digitalRead(mPin); 48 49 if (!ajustaH) { 50 adjustTime(3600); 51 } 52 53 if (!ajustaM) { 54 adjustTime(60); 55 } 56 57 h = hour(); 58 m = minute(); 59 Serial.print (hour()); 60 Serial.print(":"); 61 Serial.print (minute()); 62 Serial.print(":"); 63 Serial.print (second()); 64 Serial.println(); 65 66 delay(000); 67 68 if ( h > 12) 69 { 70 h = (h - 12); 71 } 72 73 74 75 76 77 // now set hour 78 if (h == 1) 79 { 80 display.print("One "); 81 } 82 83 84 85 if (h == 2) 86 { 87 display.print("Two "); 88 } 89 90 if (h == 3) 91 { 92 display.print("Three "); 93 } 94 95 96 97 if (h == 4) 98 { 99 display.print("Four "); 100 } 101 102 103 if (h == 5) 104 { 105 display.print("Five "); 106 } 107 108 109 110 if (h == 6) 111 { 112 display.print("Six "); 113 } 114 115 116 117 if (h == 7) 118 { 119 display.print("Seven "); 120 } 121 122 123 124 if (h == 8) 125 { 126 display.print("Eight "); 127 } 128 129 130 if (h == 9) 131 { 132 display.print("Nine "); 133 } 134 135 136 137 if (h == 10) 138 { 139 display.print("Ten "); 140 } 141 142 143 144 if (h == 11) 145 { 146 display.print("Eleven "); 147 } 148 149 150 151 if (h == 12) 152 { 153 display.print("Twelve "); 154 } 155 156 if (h == 0) 157 { 158 display.print("Twelve "); 159 } 160 161 162 // now set minute 163 if (m == 0) 164 { 165 display.print("O'Clock "); 166 } 167 168 169 170 if (m == 1) 171 { 172 display.print(" o-One "); 173 } 174 175 176 177 if (m == 2) 178 { 179 display.print(" o-Two "); 180 } 181 182 183 184 if (m == 3) 185 { 186 display.print(" o-Three "); 187 } 188 189 190 191 if (m == 4) 192 { 193 display.print(" o-Four "); 194 } 195 196 197 198 if (m == 5) 199 { 200 display.print(" o-Five "); 201 } 202 203 204 205 if (m == 6) 206 { 207 display.print(" o-Six "); 208 } 209 210 211 212 if (m == 7) 213 { 214 display.print(" o-Seven "); 215 } 216 217 218 219 if (m == 8) 220 { 221 display.print(" o-Eight "); 222 } 223 224 225 if (m == 9) 226 { 227 display.print(" o-Nine "); 228 } 229 230 231 232 if (m == 10) 233 { 234 display.print("Ten "); 235 } 236 237 238 239 if (m == 11) 240 { 241 display.print("Eleven "); 242 } 243 244 245 246 if (m == 12) 247 { 248 display.print("Twelve "); 249 } 250 251 252 253 if (m == 13) 254 { 255 display.print("Thirteen ");; 256 } 257 258 259 260 if (m == 14) 261 { 262 display.print("Fourteen "); 263 } 264 265 266 if (m == 15) 267 { 268 display.print("Fifteen "); 269 } 270 271 272 if (m == 16) 273 { 274 display.print("Sixteen "); 275 } 276 277 278 279 if (m == 17) 280 { 281 display.print("Seventeen "); 282 } 283 284 285 286 if (m == 18) 287 { 288 display.print("Eighteen "); 289 } 290 291 292 293 if (m == 19) 294 { 295 display.print("Ninteen "); 296 } 297 298 299 300 if (m == 20) 301 { 302 display.print("Twenty "); 303 } 304 305 306 307 if (m == 21) 308 { 309 display.print("Twenty-One "); 310 } 311 312 313 314 if (m == 22) 315 { 316 display.print("Twenty-Two "); 317 } 318 319 320 321 if (m == 23) 322 { 323 display.print("Twenty-Three "); 324 } 325 326 327 328 if (m == 24) 329 { 330 display.print("Twenty-Four "); 331 } 332 333 334 335 if (m == 25) 336 { 337 display.print("Twenty-Five "); 338 } 339 340 341 if (m == 26) 342 { 343 display.print("Twenty-Six "); 344 } 345 346 347 348 if (m == 27) 349 { 350 display.print("Twenty-Seven "); 351 } 352 353 354 355 if (m == 28) 356 { 357 display.print("Twenty-Eight ");; 358 } 359 360 361 362 if (m == 29) 363 { 364 display.print("Twenty-Nine "); 365 } 366 367 368 369 if (m == 30) 370 { 371 display.print("Thirty "); 372 } 373 374 375 376 if (m == 31) 377 { 378 display.print("Thirty-One "); 379 } 380 381 382 383 if (m == 32) 384 { 385 display.print("Thirty-Two "); 386 } 387 388 389 390 if (m == 33) 391 { 392 display.print("Thirty-Three "); 393 } 394 395 396 397 if (m == 34) 398 { 399 display.print("Thirty-Four "); 400 } 401 402 403 if (m == 35) 404 { 405 display.print("Thirty-Five ");; 406 } 407 408 409 410 if (m == 36) 411 { 412 display.print("Thirty-Six "); 413 } 414 415 416 417 if (m == 37) 418 { 419 display.print("Thirty-Seven "); 420 } 421 422 423 424 if (m == 38) 425 { 426 display.print("Thirty-Eight "); 427 } 428 429 430 431 if (m == 39) 432 { 433 display.print("Thirty-Nine "); 434 } 435 436 437 438 if (m == 40) 439 { 440 display.print("Forty "); 441 } 442 443 444 445 if (m == 41) 446 { 447 display.print("Forty-One "); 448 } 449 450 451 452 if (m == 42) 453 { 454 display.print("Forty-Two "); 455 } 456 457 458 459 if (m == 43) 460 { 461 display.print("Forty-Three "); 462 } 463 464 465 466 if (m == 44) 467 { 468 display.print("Forty-Four "); 469 } 470 471 472 473 if (m == 45) 474 { 475 display.print("Forty-Five "); 476 } 477 478 479 480 if (m == 46) 481 { 482 display.print("Forty-Six "); 483 } 484 485 486 487 if (m == 47) 488 { 489 display.print("Forty-Seven "); 490 } 491 492 493 494 if (m == 48) 495 { 496 display.print("Forty-Eight "); 497 } 498 499 500 501 if (m == 49) 502 { 503 display.print("Forty-Nine "); 504 } 505 506 507 508 if (m == 50) 509 { 510 display.print("Fifty "); 511 } 512 513 514 515 if (m == 51) 516 { 517 display.print("Fifty-One "); 518 } 519 520 521 if (m == 52) 522 { 523 display.print("Fifty-Two "); 524 } 525 526 527 528 if (m == 53) 529 { 530 display.print("Fifty-Three "); 531 } 532 533 534 if (m == 54) 535 { 536 display.print("Fifty-Four ");; 537 } 538 539 540 541 if (m == 55) 542 { 543 display.print("Fifty-Five "); 544 } 545 546 547 548 if (m == 56) 549 { 550 display.print("Fifty-Six "); 551 } 552 553 554 555 if (m == 57) 556 { 557 display.print("Fifty-Seven "); 558 } 559 560 561 if (m == 58) 562 { 563 display.print("Fifty-Eight "); 564 } 565 566 567 568 if (m == 59) 569 { 570 display.print("Fifty-Nine "); 571 } 572 if (hour() < 12) 573 { 574 display.setCursor(38, 24); 575 display.print("AM"); 576 } 577 if (hour() == 12) 578 { 579 display.setCursor(38, 24); 580 display.print("PM"); 581 } 582 if (hour() == 24) 583 { 584 display.setCursor(38, 24); 585 display.print("AM"); 586 } 587 588 if (hour() > 12) 589 { 590 display.setCursor(38, 24); 591 592 display.print("PM"); 593 594 } 595} 596 597void loop() { 598 599 Display(); 600 display.setCursor(30, 0); 601 display.print("It is"); 602 display.setCursor(0, 12); 603 604 display.display(); 605 delay(1000); 606 display.clearDisplay(); 607} 608 609 610 611
simple word clock
arduino
1#include <Wire.h> 2#include <Time.h> 3#include <SPI.h> 4#include <TimeLib.h> 5 6#include <Adafruit_GFX.h> 7#include <Adafruit_SSD1306.h> 8#define OLED_RESET 4 9Adafruit_SSD1306 display(OLED_RESET); 10#if (SSD1306_LCDHEIGHT != 32) 11#error("Height incorrect, please fix Adafruit_SSD1306.h!"); 12#endif 13byte mm1, mm5, h, m, s; 14byte ultM = 10, ultH = 10; 15byte hPin = 3, mPin = 2; 16boolean ajustaH = true, ajustaM = true; 17 18 19void setup() { 20 21 Serial.begin(9600); 22 pinMode(hPin, INPUT_PULLUP); 23 pinMode(mPin, INPUT_PULLUP); 24 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) 25 // init done 26 //Clear the buffer. 27 display.clearDisplay(); 28 text(); 29 30} 31 32 33 34void text(void) { 35 display.setTextSize(1); 36 display.setTextColor(WHITE); 37 38 39 40 41} 42 43void Display() { 44 45 // Setup of Hours & Minutes 46 ajustaH = digitalRead(hPin); 47 ajustaM = digitalRead(mPin); 48 49 if (!ajustaH) { 50 adjustTime(3600); 51 } 52 53 if (!ajustaM) { 54 adjustTime(60); 55 } 56 57 h = hour(); 58 m = minute(); 59 Serial.print (hour()); 60 Serial.print(":"); 61 Serial.print (minute()); 62 Serial.print(":"); 63 Serial.print (second()); 64 Serial.println(); 65 66 delay(000); 67 68 if ( h > 12) 69 { 70 h = (h - 12); 71 } 72 73 74 75 76 77 // now set hour 78 if (h == 1) 79 { 80 display.print("One "); 81 } 82 83 84 85 if (h == 2) 86 { 87 display.print("Two "); 88 } 89 90 if (h == 3) 91 { 92 display.print("Three "); 93 } 94 95 96 97 if (h == 4) 98 { 99 display.print("Four "); 100 } 101 102 103 if (h == 5) 104 { 105 display.print("Five "); 106 } 107 108 109 110 if (h == 6) 111 { 112 display.print("Six "); 113 } 114 115 116 117 if (h == 7) 118 { 119 display.print("Seven "); 120 } 121 122 123 124 if (h == 8) 125 { 126 display.print("Eight "); 127 } 128 129 130 if (h == 9) 131 { 132 display.print("Nine "); 133 } 134 135 136 137 if (h == 10) 138 { 139 display.print("Ten "); 140 } 141 142 143 144 if (h == 11) 145 { 146 display.print("Eleven "); 147 } 148 149 150 151 if (h == 12) 152 { 153 display.print("Twelve "); 154 } 155 156 if (h == 0) 157 { 158 display.print("Twelve "); 159 } 160 161 162 // now set minute 163 if (m == 0) 164 { 165 display.print("O'Clock "); 166 } 167 168 169 170 if (m == 1) 171 { 172 display.print(" o-One "); 173 } 174 175 176 177 if (m == 2) 178 { 179 display.print(" o-Two "); 180 } 181 182 183 184 if (m == 3) 185 { 186 display.print(" o-Three "); 187 } 188 189 190 191 if (m == 4) 192 { 193 display.print(" o-Four "); 194 } 195 196 197 198 if (m == 5) 199 { 200 display.print(" o-Five "); 201 } 202 203 204 205 if (m == 6) 206 { 207 display.print(" o-Six "); 208 } 209 210 211 212 if (m == 7) 213 { 214 display.print(" o-Seven "); 215 } 216 217 218 219 if (m == 8) 220 { 221 display.print(" o-Eight "); 222 } 223 224 225 if (m == 9) 226 { 227 display.print(" o-Nine "); 228 } 229 230 231 232 if (m == 10) 233 { 234 display.print("Ten "); 235 } 236 237 238 239 if (m == 11) 240 { 241 display.print("Eleven "); 242 } 243 244 245 246 if (m == 12) 247 { 248 display.print("Twelve "); 249 } 250 251 252 253 if (m == 13) 254 { 255 display.print("Thirteen ");; 256 } 257 258 259 260 if (m == 14) 261 { 262 display.print("Fourteen "); 263 } 264 265 266 if (m == 15) 267 { 268 display.print("Fifteen "); 269 } 270 271 272 if (m == 16) 273 { 274 display.print("Sixteen "); 275 } 276 277 278 279 if (m == 17) 280 { 281 display.print("Seventeen "); 282 } 283 284 285 286 if (m == 18) 287 { 288 display.print("Eighteen "); 289 } 290 291 292 293 if (m == 19) 294 { 295 display.print("Ninteen "); 296 } 297 298 299 300 if (m == 20) 301 { 302 display.print("Twenty "); 303 } 304 305 306 307 if (m == 21) 308 { 309 display.print("Twenty-One "); 310 } 311 312 313 314 if (m == 22) 315 { 316 display.print("Twenty-Two "); 317 } 318 319 320 321 if (m == 23) 322 { 323 display.print("Twenty-Three "); 324 } 325 326 327 328 if (m == 24) 329 { 330 display.print("Twenty-Four "); 331 } 332 333 334 335 if (m == 25) 336 { 337 display.print("Twenty-Five "); 338 } 339 340 341 if (m == 26) 342 { 343 display.print("Twenty-Six "); 344 } 345 346 347 348 if (m == 27) 349 { 350 display.print("Twenty-Seven "); 351 } 352 353 354 355 if (m == 28) 356 { 357 display.print("Twenty-Eight ");; 358 } 359 360 361 362 if (m == 29) 363 { 364 display.print("Twenty-Nine "); 365 } 366 367 368 369 if (m == 30) 370 { 371 display.print("Thirty "); 372 } 373 374 375 376 if (m == 31) 377 { 378 display.print("Thirty-One "); 379 } 380 381 382 383 if (m == 32) 384 { 385 display.print("Thirty-Two "); 386 } 387 388 389 390 if (m == 33) 391 { 392 display.print("Thirty-Three "); 393 } 394 395 396 397 if (m == 34) 398 { 399 display.print("Thirty-Four "); 400 } 401 402 403 if (m == 35) 404 { 405 display.print("Thirty-Five ");; 406 } 407 408 409 410 if (m == 36) 411 { 412 display.print("Thirty-Six "); 413 } 414 415 416 417 if (m == 37) 418 { 419 display.print("Thirty-Seven "); 420 } 421 422 423 424 if (m == 38) 425 { 426 display.print("Thirty-Eight "); 427 } 428 429 430 431 if (m == 39) 432 { 433 display.print("Thirty-Nine "); 434 } 435 436 437 438 if (m == 40) 439 { 440 display.print("Forty "); 441 } 442 443 444 445 if (m == 41) 446 { 447 display.print("Forty-One "); 448 } 449 450 451 452 if (m == 42) 453 { 454 display.print("Forty-Two "); 455 } 456 457 458 459 if (m == 43) 460 { 461 display.print("Forty-Three "); 462 } 463 464 465 466 if (m == 44) 467 { 468 display.print("Forty-Four "); 469 } 470 471 472 473 if (m == 45) 474 { 475 display.print("Forty-Five "); 476 } 477 478 479 480 if (m == 46) 481 { 482 display.print("Forty-Six "); 483 } 484 485 486 487 if (m == 47) 488 { 489 display.print("Forty-Seven "); 490 } 491 492 493 494 if (m == 48) 495 { 496 display.print("Forty-Eight "); 497 } 498 499 500 501 if (m == 49) 502 { 503 display.print("Forty-Nine "); 504 } 505 506 507 508 if (m == 50) 509 { 510 display.print("Fifty "); 511 } 512 513 514 515 if (m == 51) 516 { 517 display.print("Fifty-One "); 518 } 519 520 521 if (m == 52) 522 { 523 display.print("Fifty-Two "); 524 } 525 526 527 528 if (m == 53) 529 { 530 display.print("Fifty-Three "); 531 } 532 533 534 if (m == 54) 535 { 536 display.print("Fifty-Four ");; 537 } 538 539 540 541 if (m == 55) 542 { 543 display.print("Fifty-Five "); 544 } 545 546 547 548 if (m == 56) 549 { 550 display.print("Fifty-Six "); 551 } 552 553 554 555 if (m == 57) 556 { 557 display.print("Fifty-Seven "); 558 } 559 560 561 if (m == 58) 562 { 563 display.print("Fifty-Eight "); 564 } 565 566 567 568 if (m == 59) 569 { 570 display.print("Fifty-Nine "); 571 } 572 if (hour() < 12) 573 { 574 display.setCursor(38, 24); 575 display.print("AM"); 576 } 577 if (hour() == 12) 578 { 579 display.setCursor(38, 24); 580 display.print("PM"); 581 } 582 if (hour() == 24) 583 { 584 display.setCursor(38, 24); 585 display.print("AM"); 586 } 587 588 if (hour() > 12) 589 { 590 display.setCursor(38, 24); 591 592 display.print("PM"); 593 594 } 595} 596 597void loop() { 598 599 Display(); 600 display.setCursor(30, 0); 601 display.print("It is"); 602 display.setCursor(0, 12); 603 604 display.display(); 605 delay(1000); 606 display.clearDisplay(); 607} 608 609 610 611
Downloadable files
photo diagram for hookup
OLED SDA to nano pin 4, SCL to nano pin 5. Push button 1 to ground and to nano pin 2 sets hour. Push button 2 to ground and to nano pin 3 sets minute.
photo diagram for hookup
Comments
Only logged in users can leave comments
garysat
0 Followers
•0 Projects
0