How I reduce the number of global variable in a sketch ?

Hello everybody,

I am a newcomer in the Arduino world. My programming way isn’t very clean and I encount a memory problem.

I use 61% of the dynamic memory with my global variable on my Arduino Uno.

My sketch is a time counter to measure operating time of my Arduino Uno.

I enclose my code on this post.

Could you help me to reduce the number of global variable in my sketch please ?

Chrono_V2.ino (3.04 KB)

Stop using that unsigned long buf[256];there is no need to cache EEPROM data.

BTW you are only filling elements 0, 4, … and use one 4th of the array anyway.

      while (adresse < 256) {
        tps = EEPROMReadlong(adresse);
        buf[adresse] = tps;
        adresse = adresse + 4;

61% is pretty good. I wouldn't bother unless you need to add something which is going to occupy another 40%

I have several programs which report 98%. One is a big program highly optimised and squeezed into the available memory. The others were simple tests where I used the program once to test something and I don't need to waste time optimising something which I could throw away after use.

Finally, I have solved the problem by switching global variable to local variable.

Now I use 11% of the dynamic memory.

Thank you for your comments

Going from static to dynamic memory does not change anything.

There is still no need for that big array, work on your algorithm to access EEPROM directly when needed.