Hi,
i made my first library, but after using it in my main project performance dropped A LOT. Is using classes that heavy for arduino or i have done something wrong?
I was using 10 standard millis timers and 13 comparisons like this:
if (previousValue != currentValue) {
previousValue = currentValue;
doSomething();
}
Then i used 23 objects and my lps counter* values droped from ~11 800 to ~70. //this values are true when touchscreen isn't active. Other functions sometimes drop this value to 10K. During drawing of tft its less then 10 lps.
(*every time loop is closed counter increases, after a second I print it on screen and change value to 0. It give me at least some information what parts of my code take the longest to execute.)
Library .cpp file:
#include "Tasks.h"
bool Tasks::timer(unsigned long timerInterval) {
if ( (millis() - previousTimer >= timerInterval || timerForcedReset) && run) {
timerForcedReset = false;
previousTimer = millis();
return true;
} else return false;
} //time
void Tasks::timerReset() {
timerForcedReset = true;
}
bool Tasks::revise (int intValue) {
if ( (previousIntValue != intValue || reviseForcedReset) && run) {
reviseForcedReset = false;
previousIntValue = intValue;
return true;
}
else return false;
}
void Tasks::reviseReset() {
reviseForcedReset = true;
}
.h file
#ifndef Tasks_H
#define Tasks_H
#include <Arduino.h>
class Tasks {
public:
Tasks(bool run = true) {
this->run = run;
}
bool timer(unsigned long timerInterval);
void timerReset();
bool revise (int intValue);
void reviseReset();
#define FORBIT 0
private:
bool timerForcedReset;
bool reviseForcedReset;
unsigned long previousTimer;
unsigned long timerInterval;
int previousIntValue;
bool run;
};
#endif
I didn't change anything in my main project besides changing timers and checking if values are changed.
Others library for my arduino mega i don't think was that heavy, but.. i was using only ~10 objects before my liblary, now its over 30.
I still have over 5K of free SRAM memory during use (not during saving code to arduino) and over 80% free memory for sketch.
Is using objects/classes that heavy for arduino or i have done something wrong?
I was planning to move my project to ESP already, but i don't want to take with me buggy code that works only because other processor is faster.
Thanks in advance, u're better then any teacher i had ^^
