Good day everyone! I'm making my project using fastLED lib to make a 24

Good day everyone! I’m making my project using fastLED lib to make a 24 sec shotclock. i already have the code and greatly it is through mr @marmil . The problem is that the timing of the countdown is not exactly as to the timer. From displaying to 24 seconds, i only got 21 sec recorded video. I’m asking if how will i fix the timing of the digit display? great thanks everyone! :slight_smile:

here’s the code

here’s the video

You are using the Arduino’s internal frequency, that is not very precise. I remember having discussions about problems between FastLED and internal timers that are used for the millis() function. I thought that was fixed (or greatly improved) in a newer release of FastLED !? First pick up the latest version.

Then if that does not work and you are not too concerned with extreme clock accuracy, change 1000 in the following line…

EVERY_N_MILLISECONDS(1000){

to something bigger like 24(the seconds you want)/21(the seconds you get now)*1000 = 1143 !!!

Ooops ! just realised I messed up a just too simple calculation (AGAIN!!) Since your clock is slower than real time, you need to speed it up not slow it down like I suggested above…

so it should be 21/24 * 1000 = 875 !!

@JP_Roy Thank you very much sir! I’ll try it. :slight_smile:

it work with 1200 sir :slight_smile: @JP_Roy

Excellent !!

sir can i know the issue why is not working exactly at 1000 rate? so i can prove it to my panel in defense for my thesis. big thanks sir :slight_smile:

The FastLED Library authors +Daniel Garcia or @Mark_Kriegsman would be better to explain it but here’s my understanding of what is happening…

The internal timers rely on interrupts being enabled and FastLED must disable these interrupts while it is transmitting the LED data.

I think that FastLED attempts to correct the timers used for real time calculation. In an older version of FastLED that error correction was faulty and was supposed to be fixed or greatly improved since.

Did you get the very latest version of the FastLED library ??

@JP_Roy yes sir :slight_smile: i got 3.1.3 sir is there also a factor that i used sk6812 led strip? is the hardware of the led strip also affects the timing?

the sk6812 uses a 3-wire (clockless) data protocol and the data timing is critical and cannot be interrupted.

sir @JP_Roy i cannot use buttons to switch my countdown? to reset the countdown and start/stop?

You cannot have interrupts enabled while led data is being transmitted.

There are other methods to check the state of buttons and modify program flow accordingly.

how will i control my 24 sec shotclok sir? what will i use? i’m planing to have a controller and will communicate using wifi shield. @JP_Roy

@JP_Roy sir can i ask if how will i change the color from red to blue on the led strip using a button while looping the countdown? i manage to have a button for reset of 24 sec shotclock only using the digitalRead and digitalWrite. here’s the code sir.

https://gist.github.com/anonymous/f226b5120f450686de57795024e60be2

It is difficult for me to help you with this as I do not have the hardware on hand but I noticed that you use the same pin number (11) for the strip data and an LED !? they should be different !

For the color changing button question, it should be as simple as adding a switch on another pin, and more or less duplicating the same code used for the reset but using different variable name that will toggle the color.

Also just noticed that your Reset switch toggles the ‘running’ variable but apart from turning on an LED ( on pin 11 ???) it does nothing in your code to reset any timer !? I only guess that you did not get that part working or that sketch you posted is incomplete ??

I would strongly recommend that you carefully read through and get some ‘hands-on’ the Arduino ‘built-in Examples’ that should help a lot more than I would.

I specifically recommend going through the 01.Basic, 02.Digital and 05.Control sections of the Arduino built-in Examples. In the Arduino IDE menu, just click ‘File’, then ‘Examples’, then look in the ‘built-in Examples’ section. Other sections may be helpful as well !

@JP_Roy thank you sir! i really don’t know what to do i just plug in and edit the codes and try to work the proj. If i would use another pin for the button how will the button respond to the loop of the shotclock? when it is on different pin? sorry for this dumb question sir. :slight_smile:

is there any means sir that i’ll just call a specific functions just like rest or stop/go in the arduino codes? like i’ll make my own library then call the functions and run it through the buttons? even the parts of the arduino codes, i cannot really understand it. is it possible that my codes in arduino will be object oriented sir? can you give me similar codes for this sir so i can experiment it. big thanks sir @JP_Roy :slight_smile:

Hi @Joem_Deocampo , do not be sorry about asking any questions but please be mindful of all answers.

In my humble opinion, from all your questions, you must spend some time carefully analysing AND modifying the example sketches that are included with the Arduino IDE to fully understand the basic principles. THAT is the BEST answer I can give you.

Still, I will provide some general guidance as precise or complete answers are impossible here.

Q1) If i would use another pin for the button how will the button respond to the loop of the shotclock?

A1) You should use a pin for the Reset button AND another, separate pin for the color change button and other, separate pins for any other additional switches you require for your project. All switches should be monitored continuously in your main loop and variables updated based on the switch status.

Q2) is there any means sir that i’ll just call a specific functions just like rest or stop/go in the arduino codes?

A2) Yes.

Q3) like i’ll make my own library then call the functions and run it through the buttons?

A3) That sounds a bit above you current programming skill level but that is possible although you can probably achieve all your design goals within your sketch and without going through the complexity of creating your own library. But that is possible.

Q4) is it possible that my codes in arduino will be object oriented sir?

A4) No.

Q5) can you give me similar codes for this sir so i can experiment it.

A5) Similar code exists in the built-in examples that I already suggested to you. I will not write this sketch for you. I honestly think it would be more beneficial that YOU understand the basic examples first and then possibly all your questions will be answered.

However, if you still have questions after that then come back with your more specific question AND your sketch in pastebin or gist.

@JP_Roy I made it sir and big thanks to you you made it possible! My next probelm is the esp to esp communication. can i ask for insights regarding this communication. I have 1 AP and 2 stations. The AP sends string that will be interpreted in the stations which are the shotclock displays. I made it but my problem is that it has 3 sec delay that if after i press the button, the stations (digit display) will respond after 3 sec the buttons is pressed, sometimes 1 sec sometime 2. and sometimes there is no received data. How will i fix this sir? Big thanks! :slight_smile: