Checking Real Life Time

Hello everyone. I'm new to Arduino and have been tasked with doing essentially anything of my choosing to demonstrate I have a basic understanding of how it works for a class I am in. My idea is to create a binary clock with LEDs. The idea is to have them light up to represent 1 and be off to represent 0 and then with the string of 12 LEDs I can display the time up to the 12th hour and the 59th minute.

For example:

1:13 in binary would be 1:1101 so I would have the right most LED on the left of the divider (the divider is essentially the : on a digital clock) light up to represent 0001 and 3 of the 4 most right LED's of the right side of the divider light up to display 00001101 for 1 and 13 getting 1:13.

I am debating putting another LED to indicate either AM or PM.

My problem is with the coding. I do not know how to get the code to check the current time. I have tried using the now() function, but when I run the code I get an error saying now() is not defined, so I initialized it and was unsuccessful. I downloaded and imported the Time.h library but that was not helpful either.

Please don't write the entire code for the project I have described, I just don't know how to get the Arduino to register the current eastern standard time.

Thank you. :)

(deleted)

You need a real time clock (RTC) module that provides the time. Arduino does not have a built in clock. You can easily google how to use it.

2:13 in binary would be 1:1101

Are you sure?

Pete

el_supremo:

2:13 in binary would be 1:1101

Are you sure?

Don't worry, The folks looking at 1:1101 won't know either :)

...R

If you are going to add an AM/PM LED you might as well just add a bit to the hours field to get 24-hour time. You can still fit hours and minute into 11 bits.

const byte HourPins[5] = {2,3,4,5,6};
const byte MinutePins[6] = {7,8,9,10,11,12};

for (byte i=0; i<5; i++)
{
  digitalWrite(HourPins[i], (hour>>i) & 1);
}
for (byte i=0; i<6; i++)
{
  digitalWrite(MinutePins[i], (minute>>i) & 1);
}

el_supremo: Are you sure?

Pete

Very very stupid mistake on my part. 10:1101 would be 2:13

Meant 1:13. But was thinking 2:13 for some reason. I've edited my original post.

johnwasser:
If you are going to add an AM/PM LED you might as well just add a bit to the hours field to get 24-hour time. You can still fit hours and minute into 11 bits.

const byte HourPins[5] = {2,3,4,5,6};

const byte MinutePins[6] = {7,8,9,10,11,12};

for (byte i=0; i<5; i++)
{
  digitalWrite(HourPins[i], (hour>>i) & 1);
}
for (byte i=0; i<6; i++)
{
  digitalWrite(MinutePins[i], (minute>>i) & 1);
}

I am a little confused on your suggestion. Are you saying to program the LED’s in military time so I have 0-23 hours? If so, I have thought about this, and I would need an extra LED to represent the numbers from 16-23, but I would also need another LED to display AM or PM so that waasn’t really an issue, I just thought it would be easier to install the AM PM indicator.

Also it seems more difficult to program more numbers (13-23, 0) than to just add an LED and have it switch on depending on the time AM or PM. Am I being naive? Forgive me. The extent of my programming experience is in C++ creating a program that computes factorials. The goal of my class is not to teach the programming but the electronics part, and as a result, my professor seems to be not too educated on the programming side of things, and he redirects many questions to the TA who is more experienced in the subject matter, but he intimidates me.

Feel free to adopt the code to your feeling :slight_smile:

I’d choose the most simple coding solution…