//OLED Word Clock
#include <Wire.h>
#include"RTClib.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
// Display output
#define MINUTES
#define MTEN
#define HALF
#define PAST
#define THREE
#define ITIS
#define TWENTY
#define TO
#define TWO
#define SIX
#define TWELVE
#define HFIVE
#define SEVEN
#define OCLOCK
#define ONE
#define QUARTER
#define EIGHT
#define MFIVE
#define ARDUINO
#define ELEVEN
#define HTEN
#define NINE
#define FOUR
#define RBK
int hour=0, minute=0, second=0;
static unsigned long msTick =0; // the number of Millisecond Ticks since we last
// incremented the second counter
int selftestmode; // 1 = in self test - flash display
char Display1=0, Display2=0, Display3=0;
// RTC DEFINE-
RTC_DS1307 RTC ;
void setup()
{
Serial.begin(9600); // setup the serial port to 9600 baud
Wire.begin();
RTC.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done
//Clear the buffer.
display.clearDisplay();
//draw scrolling text
testscrolltext();
delay(2);
display.clearDisplay();
if ( RTC.isrunning()) {
DateTime now = RTC.now();
display.clearDisplay();
}
DateTime now = RTC.now();
msTick=millis(); // Initialise the msTick counter
if ( RTC.isrunning() ) {
// Get the current time and date from the RTC chip
second=now.second();
minute=now.minute();
hour=now.hour();
display.clearDisplay();
}
displaytime(); // display the current time
}
void testscrolltext(void) {
display.setTextSize(1);
display.setTextColor(WHITE);
}
void displaytime(void){
// start by clearing the display to a known state
display.clearDisplay();
display.setCursor(30,0);
display.print("It is");
display.println(" ");
display.display();
// now we display the appropriate minute counter
if ((minute>4) && (minute<10)) {
MFIVE;
MINUTES;
display.setCursor(1,10);
display.print("Five Minutes ");
display.println(" ");
display.display();
}
if ((minute>9) && (minute<10)) {
MTEN;
MINUTES;
display.setCursor(1,10);
display.print("Ten Minutes ");
display.println(" ");
display.display();
}
if ((minute>14) && (minute<20)) {
QUARTER;
display.setCursor(1,10);
display.print("A Quarter ");
display.println(" ");
display.display();
}
if ((minute>19) && (minute<25)) {
TWENTY;
MINUTES;
display.setCursor(1,10);
display.print("Twenty Minutes ");
display.println(" ");
display.display();
}
if ((minute>24) && (minute<30)) {
TWENTY;
MFIVE;
MINUTES;
display.setCursor(1,10);
display.print("Twenty Five Minutes ");
display.println(" ");
display.display();
}
if ((minute>29) && (minute<35)) {
HALF;
display.setCursor(1,10);
display.print("Half ");
display.println(" ");
display.display();
}
if ((minute>34) && (minute<40)) {
TWENTY;
MFIVE;
display.setCursor(1,10);
display.print("Twenty Five Minutes ");
display.println(" ");
display.display();
}
if ((minute>39) && (minute<45)) {
TWENTY;
MINUTES;
display.setCursor(1,10);
display.print("Twenty Minutes ");
display.println(" ");
display.display();
}
if ((minute>44) && (minute<50)) {
QUARTER;
display.setCursor(1,10);
display.print("A Quarter ");
display.println(" ");
display.display();
}
if ((minute>49) && (minute<55)) {
MTEN;
MINUTES;
display.setCursor(1,10);
display.print("Ten Minutes ");
display.println(" ");
display.display();
}
if (minute>54) {
MFIVE;
MINUTES;
display.setCursor(1,10);
display.print("Five Minutes ");
display.println(" ");
display.display();
}
if ((minute <5))
{
switch (hour) {
case 1:
case 13:
ONE;
display.print("One O'Clock");
display.display();
break;
case 2:
case 14:
TWO;
display.print("Two O'Clock");
display.display();
break;
case 3:
case 15:
THREE;
display.print("Three O'Clock");
display.display();
break;
case 4:
case 16:
FOUR;
display.print("Four O'Clock");
display.display();
break;
case 5:
case 17:
HFIVE;
display.print("Five O'Clock");
display.display();
break;
case 6:
case 18:
SIX;
display.print("Six O'Clock");
display.display();
break;
case 7:
case 19:
SEVEN;
display.print("Seven O'Clock");
display.display();
break;
case 8:
case 20:
EIGHT;
display.print("Eight O'Clock");
display.display();
break;
case 9:
case 21:
NINE;
display.print("Nine O'Clock");
display.display();
break;
case 10:
case 22:
HTEN;
display.print("Ten O'Clock");
display.display();
break;
case 11:
case 23:
ELEVEN;
display.print("Eleven O'Clock");
display.display();
break;
case 0:
case 12:
TWELVE;
display.print("Twelve O'Clock");
display.display();
break;
}
} else
if ((minute < 35) && (minute >4))
{
PAST;
display.print("Past ");
display.display();
switch (hour) {
case 1:
case 13:
ONE;
display.print("One O'Clock");
display.display();
break;
case 2:
case 14:
TWO;
display.print("Two O'Clock");
display.display();
break;
case 3:
case 15:
THREE;
display.print("Three O'Clock");
display.display();
break;
case 4:
case 16:
FOUR;
display.print("Four O'Clock");
display.display();
break;
case 5:
case 17:
HFIVE;
display.print("Five O'Clock");
display.display();
break;
case 6:
case 18:
SIX;
display.print("Six O'Clock");
display.display();
break;
case 7:
case 19:
SEVEN;
display.print("Seven O'Clock");
display.display();
break;
case 8:
case 20:
EIGHT;
display.print("Eight O'Clock");
display.display();
break;
case 9:
case 21:
NINE;
display.print("Nine O'Clock");
display.display();
break;
case 10:
case 22:
HTEN;
display.print("Ten O'Clock");
display.display();
break;
case 11:
case 23:
ELEVEN;
display.print("Eleven O'Clock");
display.display();
break;
case 0:
case 12:
TWELVE;
display.print("Twelve O'Clock");
display.display();
break;
}
}
else
{
// if we are greater than 34 minutes past the hour then display
// the next hour, as we will be displaying a 'to' sign
TO;
display.print("To ");
display.display();
switch (hour) {
case 1:
case 13:
TWO;
display.print("Two O'Clock");
display.display();
break;
case 14:
case 2:
THREE;
display.print("Three O'Clock");
display.display();
break;
case 15:
case 3:
FOUR;
display.print("Four O'Clock");
display.display();
break;
case 4:
case 16:
HFIVE;
display.print("Five O'Clock");
display.display();
break;
case 5:
case 17:
SIX;
display.print("Six O'Clock");
display.display();
break;
case 6:
case 18:
SEVEN;
display.print("Seven O'Clock");
display.display();
break;
case 7:
case 19:
EIGHT;
display.print("Eight O'Clock");
display.display();
break;
case 8:
case 20:
NINE;
display.print("Nine O'Clock");
display.display();
break;
case 9:
case 21:
HTEN;
display.print("Ten O'Clock");
display.display();
break;
case 10:
case 22:
ELEVEN;
display.print("Eleven O'Clock");
display.display();
break;
case 11:
case 23:
TWELVE;
display.print("Twelve O'Clock");
display.display();
break;
case 0:
case 12:
ONE;
display.print("One O'Clock");
display.display();
break;
}
}
}
void loop()
{
DateTime now = RTC.now();
second=now.second();
minute=now.minute();
hour=now.hour();
if ( millis() - msTick >5000) {
msTick=millis();
digitalWrite(13,HIGH);
delay(50);
digitalWrite(13,LOW);
delay(50);
digitalWrite(13,HIGH);
delay(50);
digitalWrite(13,LOW);
}
if (second==59) // Update the display every 1 minute...
{
displaytime();
}
}
Comments
Please log in or sign up to comment.