Making an led clock

So im woundering if someone can guide i want to have led 1-4 another 2 rowes of led and i want to have leds light up for the time so if its 2:32 i want the second led in 1-4 to be lit up then the 6th led i. 1-11 and second led in 1-12 to be lit up so i want to have a scrip to say if min == 1,11,21,31,41,51 then led 1 would light up but if min == 2,12,22,32,42,52 then the seconed led to be lit up. I hope i made sence.

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

Maybe some diagrams would help.

Dave

dastels

Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

Re: Making an led clock

So im not at a computer at the moment but
I the rtc say its 6:52 then i want it to gave 3 scripts one for the first row to check
One script for the second row to check
And one for the hour row but if its not that number for that led say led for the hour 5 that would be off till the rtc says its 5pm or am.
Led 1 2 3 4 Minutes row 1
Led 5 10 15 20 25 30 35 40 45 50 55 minutes row 2
Led 1 2 3 4 5 6 7 8 9 10 11 12 hours
So numbers are leds so for instance if its 6:52 number 2 in row 1 would be lit up
The 50 led would be lit up
The number 6 led would be lit up

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

OK. That does it. I understand what you are trying now.

You need 27 leds. NeoPixels would probably be the easiest to work with. The 3 rows could be connected as one 27 pixel strip. Pixels 0-3 would be minutes, 4-14 would be 5 minute increments, and 15-25 would be for hours.

Given the time (hours & minutes), computing which Pixels should be lit won't be hard.

I would probably use a Feather M4 Express https://www.adafruit.com/product/3857 and the RTC featherwing https://www.adafruit.com/product/3028. The Prop Maker Wing https://www.adafruit.com/product/4145 might be useful as well, it will help with the NeoPixels as well as provide an speaker amplifier if you wanted to add chimes or such to it. It has other features that may or may not be useful for your project.

Dave

dastels

Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

Re: Making an led clock

Oh im just using leds i have them and the i/o expanders but its just the scripts thats missing i have the rtc script download that i can use i just dont know how to call the minute and hour and to tell the one led hay this is your numbers.

I have idea on how i like it set up too and to permanently mount it

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

Yes, Legs and IO expanders are another way to do it.

Just work on the code a little at a time, don't try to make it all work at once.

dastels

Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

Re: Making an led clock

i was think of a code like this but i cant figure it out if you can guide me
if (now.minute() == 1, 11, 21, 31, 41, 51){
mcp.pinMode(0, HIGH);
}
else{
mcp.pinMode(0, LOW);}

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

Look at the remainder operator ( % ) https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/remainder/ If you divide something by 10 in integer math the remainder is the ones digit.

and...integer division of a 2 digit number by 10 gives the tens digit.

Fellow hobbyist
Keith

kcl1s

Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Making an led clock

I get the ones and tens place but how would that go into a script to say hay this diget you got turn light off but if not dot turn light on why couldn't i just say hay if minute equels to x then turn pin on if it does not match then turn pin off.

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

Sure you can use the logical or operator ( || ) https://www.arduino.cc/reference/en/language/structure/boolean-operators/logicalor/ for each of your if statements as in
if (now.minute() == 1 || now.minute() == 11 || ......) { for all your numbers.
Or you could use the remainder operator if ((now.minute() %10) == 1) {
Either one will yield the same condition. Since I assume you are going to have similar code for each of the minutes I would go with the one that requires less typing and memory.

To continue your learning you may want to study up on arrays https://www.arduino.cc/reference/en/language/variables/data-types/array/ Using arrays for your MCP pin numbers could make your code very compact.

Keith

kcl1s

Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Making an led clock

After thinking some, even without arrays, if you wire it up right you should be able to set your tens and ones minute leds with just 3 lines of code. You would need to wire mcp pins 0-9 to ones 0-9 leds and mcp pins 10-15 to the tens 0-5 leds. Then this code should light the correct 2 leds.

Code: Select all | TOGGLE FULL SIZE
`  mcp.writeGPIOAB(0); //clear all leds first  mcp.digitalWrite((now.minute() % 10), HIGH);  mcp.digitalWrite(((now.minute() / 10) + 10), HIGH);`

You may want to only call this once a minute or you may get some unwanted flashing when you clear all the leds

Keith

kcl1s

Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Making an led clock

i see what your saying but i wont have 1 led for each min tho take this for example https://vimeo.com/281662044 each number and dot would be an led and the marble would be the led be on if there is no marble the led would be off but for my project of course would be no marbles at all just code and leds

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

In your case you would be dividing/modding by 5 instead of 10.

dastels

Posts: 6456
Joined: Tue Oct 20, 2015 3:22 pm

Re: Making an led clock

kcl1s wrote:After thinking some, even without arrays, if you wire it up right you should be able to set your tens and ones minute leds with just 3 lines of code. You would need to wire mcp pins 0-9 to ones 0-9 leds and mcp pins 10-15 to the tens 0-5 leds. Then this code should light the correct 2 leds.

Code: Select all | TOGGLE FULL SIZE
`  mcp.writeGPIOAB(0); //clear all leds first  mcp.digitalWrite((now.minute() % 10), HIGH);  mcp.digitalWrite(((now.minute() / 10) + 10), HIGH);`

You may want to only call this once a minute or you may get some unwanted flashing when you clear all the leds

Keith

To start im doing the 1,2,3,4 leds first and they only need 1 pin each all it has to do is check if those numbers are in the one place on the rtc if rtc says its :41 the it would turn on the 1 led. If you guys are explaning how im not seeing it once i figure out those 4 leds then i can dup for the next 2 rows

LitingWolf

Posts: 41
Joined: Thu Jan 02, 2020 3:03 pm

Re: Making an led clock

if (now.minute() == 1, 11, 21, 31, 41, 51){

Thought you were looking for the ones place digit. I guess you are doing something else. Ignore my posts.

Good luck with the project.

Keith

kcl1s

Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm