Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Arduino Clock
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Clock

by pumpkinheadnick on Fri Jan 08, 2016 9:47 pm

I am using the arduino uno and also have the RTC and the LCD with the shield.
What I am trying to do is get me clock out of military time.

I am also having some weird results with the seconds it will go from 59 to 09,19,29,39,49,59,69,79,89,99,10,11,12... how do I fix this?

#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
RTC_DS1307 RTC;
#define TEAL 0x6

void setup() {
lcd.begin(16, 2);
lcd.setBacklight(TEAL);
Wire.begin();
RTC.begin();

}

void loop() {
DateTime now = RTC.now();

lcd.setCursor(0,0);

if (now.hour()>12)
{ now.hour()==now.hour() - 12;
lcd.print(now.hour(), DEC);
}

else {
lcd.print(now.hour(), DEC);
}

lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);

}

pumpkinheadnick
 
Posts: 65
Joined: Mon Jan 04, 2016 8:23 pm

Re: Arduino Clock

by pumpkinheadnick on Fri Jan 08, 2016 9:52 pm

Is it just the left over 9 from the 59, like it did not get over-ridden in that space so it just stayed?

pumpkinheadnick
 
Posts: 65
Joined: Mon Jan 04, 2016 8:23 pm

Re: Arduino Clock

by pumpkinheadnick on Fri Jan 08, 2016 10:14 pm

I figured out the second problem. I believe the problem was what I suspected. I just had to add the the line

lcd.print(" ");

after

lcd.print(now.second(), DEC);

and it works now.

But I still can't get it out of military time.

pumpkinheadnick
 
Posts: 65
Joined: Mon Jan 04, 2016 8:23 pm

Re: Arduino Clock

by richl167 on Sat Jan 09, 2016 12:50 pm

I'm a neophyte building a similar project.
I believe

{ now.hour()==now.hour() - 12;


should be

{ now.hour()-= 12;

double "=" is compare, single "=" is assign.
a single "=" may work as well.

richl167
 
Posts: 1
Joined: Fri Apr 24, 2015 5:22 pm

Re: Arduino Clock

by pumpkinheadnick on Sun Jan 10, 2016 11:25 am

Yeah I recognized the double equal sign error there. I forgot to remove it when I uploaded the code, I only had it there because I was getting this error so I tested it out.

C:\Users\Nick\Documents\Arduino\LCD_Clock\LCD_Clock.ino: In function 'void loop()':

LCD_Clock:23: error: lvalue required as left operand of assignment

{ now.hour()=now.hour() - 12;

^

exit status 1
lvalue required as left operand of assignment


I am pretty sure that this error is saying is that I can't change what now.hour() is. I even tried to get around that by doing this...

if (now.hour()>12)
{now.hour()=settime;
newtime= settime - 12;
lcd.print(newtime);
}


but I still got the same error.

So I still can't figure out how to get it out of military?

pumpkinheadnick
 
Posts: 65
Joined: Mon Jan 04, 2016 8:23 pm

Re: Arduino Clock

by pumpkinheadnick on Mon Jan 11, 2016 8:56 pm

Ok so I was looking at that code again today and I noticed I had the line in red backwards I changed it and it now takes it out of military time. I have now also added am AM and PM line and the full date.

#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
RTC_DS1307 RTC;
#define TEAL 0x6
int settime;
int newtime;

void setup() {
lcd.begin(16, 2);
lcd.setBacklight(TEAL);
Wire.begin();
RTC.begin();

}

void loop() {
DateTime now = RTC.now();

lcd.setCursor(4,0);

if (now.hour()>12) //how to get it our of military time
{settime=now.hour();
newtime= settime - 12;
lcd.print(newtime);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print("PM");
}


else {
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print("AM");
}

lcd.setCursor(3,1);

lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.print(' ');
}

pumpkinheadnick
 
Posts: 65
Joined: Mon Jan 04, 2016 8:23 pm

Please be positive and constructive with your questions and comments.