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.
No description
33 Replies
pseud0
pseud04y ago
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++;?
Emu Bread
Emu BreadOP4y ago
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?
pseud0
pseud04y ago
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
Emu Bread
Emu BreadOP4y ago
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
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
8 second timer. Each second I need to do a special action, like turn on an LED.
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
How to do that? How to differentiate 2nd and 4th seconds for example?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
But my counter only tells when a second hits It can’t tell whether it is 3rd or 8th second. Can it?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
How? Oh wait The clock that says that it hits a second is not the counter? Is counter something else?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
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
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Is it relevant?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
What part exactly interrupts?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Why would it miss, though?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Ok i see the idea and concept Just don’t get it code wise What exactly in the setup interrupts?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Rofl Anyway thank you for helping.
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Got it Gonna watch this one then Do I need to close the chat?
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Or it deletes by itself Yeah
Unknown User
Unknown User4y ago
Message Not Public
Sign In & Join Server To View
Emu Bread
Emu BreadOP4y ago
Lol Ok just leave as it is
MaderDash
MaderDash3y ago
@Emu please tag this post as solved if your done.
MaderDash
MaderDash3y ago
@Emu

Did you find this page helpful?