Creating an 8 seconds timer with millis() and pow()
My apologies for posting code in picture format.
I am trying to make an 8 seconds timer of sorts, where each 8 seconds Arduino takes new commands. I am trying to do it through millis() and pow(), where ClockReference = millis() and for i command is used to increase exponents in order to keep up with ever increasing ClockReference.
On practice it doesn’t work, nothing is happening.

33 Replies
pow()
will return a double I think, so the clockrefernece divided by a double is a double, and checking floating-point numbers for equality is a no-no.
also you didn't say what board you're compiling for.
your for loop looks equally weird. condition is i++;
?Arduino Mega
With the processor of 1280
i++ is to increase to i value each loop.
If I do it with <= and => conditions would still be a no-no?
well since 10**(n) with n integer is always an integer, you just need to round and cast the result to an integer.
but then there's still no protection against going into one case more than once
I found a way of doing the timer, but now I don’t how to connect each specific command of mine to each second.
I am using if ( currentTime - prevTime >1000) {Actions; prevTime = currentTime}
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
8 second timer. Each second I need to do a special action, like turn on an LED.
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
How to do that?
How to differentiate 2nd and 4th seconds for example?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
But my counter only tells when a second hits
It can’t tell whether it is 3rd or 8th second.
Can it?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
How?
Oh wait
The clock that says that it hits a second is not the counter?
Is counter something else?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
I don’t really get what’s on your setup and thanks for your sarcasm, but I see your point. Create a new variable, that hits up every second, which then would be used to check what action to take. At the end bring it to zero.
Big thanks, appreciate it @Icesythe7 @pseud0
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Is it relevant?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
What part exactly interrupts?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Why would it miss, though?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Ok i see the idea and concept
Just don’t get it code wise
What exactly in the setup interrupts?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Rofl
Anyway thank you for helping.
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Got it
Gonna watch this one then
Do I need to close the chat?
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Or it deletes by itself
Yeah
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Lol
Ok just leave as it is
@Emu please tag this post as solved if your done.
@Emu