Go Down

Topic: Non blocking blink alternatives (Read 317 times) previous topic - next topic

malrose

I have a stepper motor I want to run with very quick blink pulses but I want a way to do it without blocking the code, I know about blink without delay but I'm unsure it can do what I want since I first want it to blink with a certain  delay, then blink with another delay in the code. example:

long interval = 1000;

at one point of the code and

long interval = 500;

at another.

I hope my question makes sense.

AWOL

You'll notice in the blink without delay example that the variable "interval" is fixed at 1000.
It is a variable so you can give it any value you like.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

malrose

To clarify it a bit more, I'd like it to run at the variable of 1000 for around 3 seconds then switch to 500. Or run at 1000 for 3 seconds then 500 for a set amount of time then 200 then go back to 1000.

AWOL

You'll have to define "around 3 seconds" a little better for the compiler, but there's nothing to stop you assigning any value you want to "interval" at any time.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

malrose

So I can change the interval inside the loop? How do I do that?

AWOL

With a simple assignment - it's a variable
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

malrose

I think I get, I just call long interval = 700; inside the loop if I want to change it, but how do I time it? How do I get it to keep track of how long it has been blinking before changing.

AWOL

Quote
I just call long interval = 700;

That looks to me like you're creating a new variable call "interval", which probably isn't what you want.

Quote
How do I get it to keep track of how long it has been blinking before changing.

I have no idea - I can't see your code - but it probably involves some calls to "millis()"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PeterH

The blink without delay example demonstrates how to run code after an interval. That code can do whatever you want, including changing the variables that control the timing of that piece of code, or variables that affect timing of other pieces of code.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up