robsworld78:
Can someone please explain how byte size works. I find the following to be very strange!
I thought doing that would save me a couple hundred bytes.
Hi Rob,
You are on the right lines, but chose the wrong type of code to place in a function.
Let me now give you an example of what I did with your earlier code you said you needed to remove.
Original (modified so would compile standalone) :-
#include <UTFT.h>
#include <SdFat.h>
#include <UTFT_tinyFAT.h>
extern uint8_t BigFont[];
UTFT myGLCD(CPLD, 38, 39, 40, 41);
UTFT_tinyFAT myFiles(&myGLCD);
void setup() {
myGLCD.setColor(255, 255, 255);
myGLCD.drawLine(0, 450, 799, 450); // on footer
myFiles.loadBitmap(376, 426, 48, 48, "schIconL.raw"); // footer home button
myFiles.loadBitmap(0, 0, 307, 59, "schPwI.raw");
myGLCD.drawLine(71, 54, 799, 54); // under header
// grid for schedule
myGLCD.drawLine(0, 259, 799, 259); //
myGLCD.drawLine(0, 414, 799, 414); //
myGLCD.drawLine(400, 259, 400, 414); //
myFiles.loadBitmap(116, 271, 54, 54, "upM.raw"); // up
myFiles.loadBitmap(116, 352, 54, 54, "downM.raw"); // down
myFiles.loadBitmap(321, 271, 54, 54, "upM.raw"); // up
myFiles.loadBitmap(321, 352, 54, 54, "downM.raw"); // down
myFiles.loadBitmap(516, 271, 54, 54, "upM.raw"); // up
myFiles.loadBitmap(516, 352, 54, 54, "downM.raw"); // down
myFiles.loadBitmap(721, 271, 54, 54, "upM.raw"); // up
myFiles.loadBitmap(721, 352, 54, 54, "downM.raw"); // down
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.print("Start Time", 125, 232);
myGLCD.print("Stop Time", 533, 232);
myGLCD.print("Hour", 26, 293);
myGLCD.print("Minute", 212, 293);
myGLCD.print("Hour", 426, 293);
myGLCD.print("Minute", 612, 293);
}
void loop() {
}
After I had a stab at optimising :-
#include <UTFT.h>
#include <SdFat.h>
#include <UTFT_tinyFAT.h>
extern uint8_t BigFont[];
UTFT myGLCD(CPLD, 38, 39, 40, 41);
UTFT_tinyFAT myFiles(&myGLCD);
void upM(int x, int y) {
myFiles.loadBitmap(x, y, 54, 54, "upM.raw"); // up
}
void dnM(int x, int y) {
myFiles.loadBitmap(x, y, 54, 54, "downM.raw"); // down
}
void myTime(int x) {
myGLCD.print("Hour", x, 293);
myGLCD.print("Minute", x + 186, 293);
}
void setup() {
myGLCD.setColor(255, 255, 255);
myGLCD.drawLine(0, 450, 799, 450); // on footer
myFiles.loadBitmap(376, 426, 48, 48, "schIconL.raw"); // footer home button
myFiles.loadBitmap(0, 0, 307, 59, "schPwI.raw");
myGLCD.drawLine(71, 54, 799, 54); // under header
// grid for schedule
myGLCD.drawLine(0, 259, 799, 259); //
myGLCD.drawLine(0, 414, 799, 414); //
myGLCD.drawLine(400, 259, 400, 414); //
upM(116, 271);
dnM(116, 352);
upM(321, 271);
dnM(321, 352);
upM(516, 271);
dnM(516, 352);
upM(721, 271);
dnM(721, 352);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.print("Start Time", 125, 232);
myGLCD.print("Stop Time", 533, 232);
myTime(26);
myTime(426);
}
void loop() {
}
Regarding what guix said about IDE version, he is absolutely right!! And this is why:-
Original version in IDE 1.0.6 sketch size 26,100 bytes Optimised version in V1.0.6 26,084 bytes
Original version in IDE 1.5.8 sketch size 21,882 bytes Optimised version in V1.5.8 21,820 bytes
You can make most efficiency savings when you are using strings of text repeatedly, that is why the functions I chose made savings, whereas the functions you chose did not. (Over simplified I know, but in essence I am right before the experts come and jump all over me!!)
Regards,
Graham