Created
October 3, 2014 17:57
-
-
Save buckeyeworldcitizen/5a181aeb94ee8e95579a to your computer and use it in GitHub Desktop.
code that reads rtc fine, displays minutes fine, but no hour displayed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Display output pin assignments | |
#define MTEN Display1=Display1 | (1<<0) | |
#define HALF Display1=Display1 | (1<<1) | |
#define QUARTER Display1=Display1 | (1<<2) | |
#define TWENTY Display1=Display1 | (1<<3) | |
#define MFIVE Display1=Display1 | (1<<4) | |
#define MINUTES Display1=Display1 | (1<<5) | |
#define PAST Display1=Display1 | (1<<6) | |
#define UNUSED1 Display1=Display1 | (1<<7) | |
#define TO Display2=Display2 | (1<<0) | |
#define ONE Display2=Display2 | (1<<1) | |
#define TWO Display2=Display2 | (1<<2) | |
#define THREE Display2=Display2 | (1<<3) | |
#define FOUR Display2=Display2 | (1<<4) | |
#define HFIVE Display2=Display2 | (1<<5) | |
#define SIX Display2=Display2 | (1<<6) | |
#define UNUSED2 Display2=Display2 | (1<<7) | |
#define SEVEN Display3=Display3 | (1<<0) | |
#define EIGHT Display3=Display3 | (1<<1) | |
#define NINE Display3=Display3 | (1<<2) | |
#define HTEN Display3=Display3 | (1<<3) | |
#define ELEVEN Display3=Display3 | (1<<4) | |
#define TWELVE Display3=Display3 | (1<<5) | |
#define OCLOCK Display3=Display3 | (1<<6) | |
#define UNUSED3 Display3=Display3 | (1<<7) | |
#include <Wire.h> | |
#include "RTClib.h" | |
RTC_DS1307 RTC; | |
#define SWHOUR 2 | |
#define BRIGHTNESS 3 | |
int hourS,minuteS,secondS,monthS,dayS = 0; | |
int hour=9, minute=30, second=00; | |
int count; | |
char Display1=0, Display2=0, Display3=0; | |
// hardware constants | |
int LEDClockPin=6; | |
int LEDDataPin=7; | |
int LEDStrobePin=8; | |
int MinuteButtonPin=2; | |
int HourButtonPin=3; | |
int PWMPin = 9; | |
void setup() | |
{ | |
Serial.begin(115200); | |
Wire.begin(); | |
RTC.begin(); | |
// initialise the hardware | |
// Check if the RTC is running. | |
if (! RTC.isrunning()) { | |
Serial.println("RTC is NOT running"); | |
} | |
// initialize the appropriate pins as outputs: | |
pinMode(LEDClockPin, OUTPUT); | |
pinMode(LEDDataPin, OUTPUT); | |
pinMode(LEDStrobePin, OUTPUT); | |
//pinMode(BrightnessPin, INPUT); | |
pinMode(MinuteButtonPin, INPUT); | |
pinMode(HourButtonPin, INPUT); | |
pinMode(PWMPin, OUTPUT); | |
displaytime(); // display the current time | |
} | |
void loop(void) | |
{ | |
Serial.println( ); | |
Serial.println(Display1, BIN); | |
Serial.println(Display2, BIN); | |
Serial.println(Display3, BIN); | |
/*analogWrite(PWMPin, analogRead(0)/4); //enable dimming via potentiometer or photoresistor*/ | |
analogWrite(PWMPin, 255); //manually set brightness level | |
getTime(); | |
displaytime(); | |
} | |
void getTime() | |
{ | |
DateTime now = RTC.now(); | |
hour = now.hour(); | |
minute = now.minute(); | |
second = now.second(); | |
// month = now.month(); | |
// day = now.day(); | |
// if( hourS >12) | |
// hour = hourS-12; | |
// | |
// if ( hourS == 0 ) | |
// hourS = 12; | |
Serial.print(now.year(), DEC); | |
Serial.print('/'); | |
Serial.print(now.month(),DEC); | |
Serial.print('/'); | |
Serial.print(now.day(),DEC); | |
Serial.print(' '); | |
Serial.print(hour); | |
Serial.print(':'); | |
Serial.print(minute); | |
Serial.print(':'); | |
Serial.print(second); | |
Serial.println(" "); | |
} | |
void ledsoff(void) { | |
Display1=0; | |
Display2=0; | |
Display3=0; | |
} | |
void WriteLEDs(void) { | |
// Now we write the actual values to the hardware | |
shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display3); | |
shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display2); | |
shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display1); | |
digitalWrite(LEDStrobePin,HIGH); | |
delay(2); | |
digitalWrite(LEDStrobePin,LOW); | |
} | |
void displaytime(void){ | |
// start by clearing the display to a known state | |
ledsoff(); | |
Serial.print("It is "); | |
// now we display the appropriate minute counter | |
if ((minute>4) && (minute<10)) { | |
MFIVE; | |
MINUTES; | |
Serial.print("Five Minutes "); | |
} | |
if ((minute>9) && (minute<15)) { | |
MTEN; | |
MINUTES; | |
Serial.print("Ten Minutes "); | |
} | |
if ((minute>14) && (minute<20)) { | |
QUARTER; | |
Serial.print("Quarter "); | |
} | |
if ((minute>19) && (minute<25)) { | |
TWENTY; | |
MINUTES; | |
Serial.print("Twenty Minutes "); | |
} | |
if ((minute>24) && (minute<30)) { | |
TWENTY; | |
MFIVE; | |
MINUTES; | |
Serial.print("Twenty Five Minutes "); | |
} | |
if ((minute>29) && (minute<35)) { | |
HALF; | |
Serial.print("Half "); | |
} | |
if ((minute>34) && (minute<40)) { | |
TWENTY; | |
MFIVE; | |
MINUTES; | |
Serial.print("Twenty Five Minutes "); | |
} | |
if ((minute>39) && (minute<45)) { | |
TWENTY; | |
MINUTES; | |
Serial.print("Twenty Minutes "); | |
} | |
if ((minute>44) && (minute<50)) { | |
QUARTER; | |
Serial.print("Quarter "); | |
} | |
if ((minute>49) && (minute<55)) { | |
MTEN; | |
MINUTES; | |
Serial.print("Ten Minutes "); | |
} | |
if (minute>54) { | |
MFIVE; | |
MINUTES; | |
Serial.print("Five Minutes "); | |
} | |
if ((minute <5)) | |
{ | |
switch (hour) { | |
case 1: | |
ONE; | |
Serial.print("One "); | |
break; | |
case 2: | |
TWO; | |
Serial.print("Two "); | |
break; | |
case 3: | |
THREE; | |
Serial.print("Three "); | |
break; | |
case 4: | |
FOUR; | |
Serial.print("Four "); | |
break; | |
case 5: | |
HFIVE; | |
Serial.print("Five "); | |
break; | |
case 6: | |
SIX; | |
Serial.print("Six "); | |
break; | |
case 7: | |
SEVEN; | |
Serial.print("Seven "); | |
break; | |
case 8: | |
EIGHT; | |
Serial.print("Eight "); | |
break; | |
case 9: | |
NINE; | |
Serial.print("Nine "); | |
break; | |
case 10: | |
HTEN; | |
Serial.print("Ten "); | |
break; | |
case 11: | |
ELEVEN; | |
Serial.print("Eleven "); | |
break; | |
case 12: | |
TWELVE; | |
Serial.print("Twelve "); | |
break; | |
} | |
OCLOCK; | |
Serial.println("O'Clock"); | |
} | |
else | |
if ((minute < 35) && (minute >4)) | |
{ | |
PAST; | |
Serial.print("Past "); | |
switch (hour) { | |
case 1: | |
ONE; | |
Serial.println("One "); | |
break; | |
case 2: | |
TWO; | |
Serial.println("Two "); | |
break; | |
case 3: | |
THREE; | |
Serial.println("Three "); | |
break; | |
case 4: | |
FOUR; | |
Serial.println("Four "); | |
break; | |
case 5: | |
HFIVE; | |
Serial.println("Five "); | |
break; | |
case 6: | |
SIX; | |
Serial.println("Six "); | |
break; | |
case 7: | |
SEVEN; | |
Serial.println("Seven "); | |
break; | |
case 8: | |
EIGHT; | |
Serial.println("Eight "); | |
break; | |
case 9: | |
NINE; | |
Serial.println("Nine "); | |
break; | |
case 10: | |
HTEN; | |
Serial.println("Ten "); | |
break; | |
case 11: | |
ELEVEN; | |
Serial.println("Eleven "); | |
break; | |
case 12: | |
TWELVE; | |
Serial.println("Twelve "); | |
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; | |
Serial.print("To "); | |
switch (hour) { | |
case 1: | |
TWO; | |
Serial.println("Two "); | |
break; | |
case 2: | |
THREE; | |
Serial.println("Three "); | |
break; | |
case 3: | |
FOUR; | |
Serial.println("Four "); | |
break; | |
case 4: | |
HFIVE; | |
Serial.println("Five "); | |
break; | |
case 5: | |
SIX; | |
Serial.println("Six "); | |
break; | |
case 6: | |
SEVEN; | |
Serial.println("Seven "); | |
break; | |
case 7: | |
EIGHT; | |
Serial.println("Eight "); | |
break; | |
case 8: | |
NINE; | |
Serial.println("Nine "); | |
break; | |
case 9: | |
HTEN; | |
Serial.println("Ten "); | |
break; | |
case 10: | |
ELEVEN; | |
Serial.println("Eleven "); | |
break; | |
case 11: | |
TWELVE; | |
Serial.println("Twelve "); | |
break; | |
case 12: | |
ONE; | |
Serial.println("One "); | |
break; | |
} | |
} | |
WriteLEDs(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment