interrupt question

GoForSmoke:
The way to do that takes an approach that is not taught in standard beginner-intermediate courses.

It's just a different way that Arduino setup() and loop() make natural.

Whatever is inside of loop() runs over and over.

So you put a block of code in loop() to watch a button or buttons that updates a global variable when a button is pressed.
It always runs with loop. It does not wait for the sketch to need to see a button press, it just runs.

And you put in another block of code that watches button status and acts when a button is indicated to have changed up/down.

All the blocks you put in get to run even if just to see whatever trigger they have has not been pulled. It is "event-driven code".

If you have no delays or blocking code, your void loop() can run 10's of times per milli. I am not joking, I've done examples doing as much as you've indicated that run at over 67000Hz on average. I know this because one block/task is a loop() counter that prints every second.

This works by the blocks using variables to control code execution instead of everything controlled through code structures.
It allows breaking the job into tasks that "run concurrent" so quickly it's smooth.

You get multiple programs running at once with communications between, but only do as much as you write.

thank you for that explanation it seems i have and idea of what todo now :slight_smile: