Can one prioritize a loop?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Can one prioritize a loop?

Post by Daft_vagabond »

Lets say I have a "main" while True-loop that reads an input, like a switch, and makes an led flash at a certain rate. Could I write a forever-loop that waits for a different input, like a button to be pressed, and once pressed it takes priority over the first loop and starts flashing the same led at a different rate, at least until the button was released?

Lets also say that, for this example, the "main" loop also drove some other peripherals. I wouldn't want the second loop to stop the main one, just to temporarily drive the led differently and leave the other peripherals to continue to be driven by the main loop.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can one prioritize a loop?

Post by dastels »

If you are using CircuitPython: No. It's not a multi tasking system so you can't have two loops running at the same time. Ther are programming techniques that can achieve a similar result. See https://learn.adafruit.com/multi-taskin ... cuitpython.

Dave

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Can one prioritize a loop?

Post by Daft_vagabond »

So the

def on_forever():

doesn't apply here?

I'll check out that link in the meantime.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: Can one prioritize a loop?

Post by dastels »

That's from Makecode. Not applicable in CircuitPython.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”