Hi, i made my first library. It works correctly, but after adding it to my big project, i think it could be done better (I think my .ino code could look cleaner). I hope u could direct me in good direction.
I need to track if the values โโof the 20 integers have changed.
So, firstly I made simple function:
bool update (int value) {
if ( previousIntValue != intValue) {
previousIntValue = intValue;
return true;
}
else {
return false;
}
}
And then in my code i just called:
if (update(X) ) doSomething1;
But since I need to check value of multiple ints, I created class:
class Tasks {
private:
int previousIntValue;
public:
bool update (int intValue) {
if (previousIntValue != intValue) {
previousIntValue = intValue;
return true;
}
else return false;
}
};
Now my .ino file looks like this:
#include "Tasks.h"
Tasks task1;
Tasks task2;
void setup() {
}
void loop() {
if (task1.update(X) ) doSomething1();
if (task2.update(Y) ) doSomething2();
}
I need to create a lot of 'task' and then keep track of them.
Is there any option to achieve something like i wrote below? :
#include "Tasks.h"
Tasks task;
void setup() {
}
void loop() {
if (task.timer(X) ) doSomething1();
if (task.timer(Y) ) doSomething2();
}
// now it would return true with every call, because one time previousInt will be compared to X and second time to Y.
Is it possible in any way? If no, is there anything u would change?
PS: I wrote class as example, I think adding my code as liblary would make it unnecessary harder to read. I also didn't wrote voids 'doSomething' or wrote int declarations (full code works), i hope it's okay and everything is understandable for u.
Also sorry for my english.
Thanks in advance!