In the following example (Arduino Nano with Adafruit 2,8" cap touch display) the snippet should look if the back button is pressed in several screens. It would be no problem to just put itI checked in a method. Is there a rule of thumb when a method uses lessthe Arduino IDE how much storage than a repetition? In my imagination a method needs more space and execution time than a normal line of code (if this is wrong please point it out!)each version takes:
Version 1, 15114 Bytes for complete program:
Version 2, 15234 Bytes for complete program:
void checkBack(TS_Point p){
if ((p.x > backBox.posx) && (p.x < backBox.posx + backBox.sidex)){
if((p.y > backBox.posy) && (p.y < backBox.posy + backBox.sidey)){
screen = MAIN1;
showMainScreen();
}
}
}
void battScreen(TS_Point p){
// some other code
// ...
checkBack(p);
}
void alarmScreen(TS_Point p){
// some other code
// ...
checkBack(p);
}
void pumpScreen(TS_Point p){
// some other code
// ...
checkBack(p);
}
As you can see, version 2 with the extra method takes 120 Bytes more storage. Is there a rule of thumb when it makes sense to create a new method instead of copying code?