DaveX
December 1, 2023, 5:57pm
33
Try thinking of a non-blocking program as a checklist of items you scan over every second, as compared to a sequential list of blocking items that must be completed before you can move on to the next stage.
Asking for a non-blocking-delay is like asking about how you check on a 30 minute laundry task while a 45 minute cake is baking. You don't block watching the oven or the laundry, you just quickly check if it the time is up, act or not, and move on to other tasks.
The @Robin2 tutorials at
From what I can see there are many tutorials about doing specific tasks with an Arduino but I have not come across any that guide a newcomer through the process of planning and implementing a program to make it easy to understand and debug.
The following 9 posts in this Thread are an attempt to fill that gap.
...R
NOTE for newcomers. The demo is entirely contained in this Post and Reply #1. There is no need to read further unless you are interested. ...added 25Sep2014
There have been a few occasions recently where newcomers seemed to have difficulty applying the "blink without delay" and "state" concepts to a sketch that is intended to manage a number of concurrent actions.
Its very time consuming to respond with suitable code examples - particularly as every case is a little different.
I have prepared…
and the different ways of extending BlinkWithoutDelay at
Introduction
A common question is to ask how to flash 2 (or more) LEDs at the same time. Typically the person asking will be using delay and will be experiencing the main problem with delay: it blocks and stops anything else from happening.
This tutorial contains several different approaches to the problem of flashing 2 or more LEDs at the same time with independent timing for each LED. The basic principles for each can all be adapted for other situations requiring multiple timers working inde…
... are all good at highlighting the shifted mode of thought.