I'm a bit experienced programmer, but this is my first Arduino project. I've created a Arduino program just with timer events. I don't need the "void loop(){..}". But the compiler requires one. How to fill the loop function best so it won't disturb the running program? Leave it empty? AFAIK will this lead this to an repeated call of this function (The explanation I found everywhere is, that the main of Arduino looks like "this: for (;;) loop();" ). I've add a "delay(100000);" in the loop hoping this will put the CPU to sleep - not wasting energy.
Is there a better solution? I searched for it but I did not found anything near this question. Maybe my Google Fu is not good enough?
Which board is this ? If it is for example an RTOS board (ESP32 etc.) then you can disable the loop() task or simply put a small delay of a few milliseconds in it.
Thanks for all of your answers. But this raises questions...
@alto777: I'm glad to share the code - but first when my project is finished. The HW wirering is complete, but neither the software (As everybody knows: Experimental code is nothing to show.. ) nor the positioning of all of the modules, etc.
Hmm. Than: what is the program doing? Nothing? This is what I want.
As far as I see a cheap copy of an mini pro. Can you tell my how to disable? Then I can read the manual and maybe got other ideas. The Idea with delay .. I've done this.
The Arduino IDE (and its predecessor "Processing") are made for simplicity of programming.
In (most of) your projects you will (1) configure hardware, (2) configure software, and (3) run a program continuously. setup() allows you to configure hardware and software one time (runs once), and loop() allows you to continuously run your program (runs forever) without creating you own "loop".
I like to use setup() as a "run once" program to see specific items. I also call other functions from setup() so those other functions "run once" and do not "loop forever" in loop().
No it doesn't. It returns to main() which then calls loop() again.
If loop() called itself recursively, the program would soon crash due to running out of stack space.
What is your reason for wanting the processor to do "nothing"? Typically, we use interrupts sparingly, very few reasonable codes do all their work within the interrupts. Instead, flags are set or variables toyed with, and the code within loop() deals with the results.
I think a much more detailed description of your needs/intent is warranted.
The code to show is usually a minimal example that proves/disproves/illustrates the problem, error or stated goal. Such an example is inevitably experimental.
I doesn't. But most microcontrollers use so little power anyway, it is often not worth saving.
If your circuit is battery powered then you might want to absolutely minimise the power consumption to maximise the battery life. This isn't as easy as you might imagine, for example:
You have to choose the right board and use sleep libraries as mentioned already.
Many boards have a power led and other components on them, and these may use more power than the microcontroller itself, when it is in a sleep mode.
It's also possible that the battery's natural self-discharge rate is higher than the microcontroller's power consumption, so choice of battery is also important.