Reduce Sketch Size

Sketch using BME280 sensor and ILI9341 TFT

The Attached sketch compiles to 31230k and works ok on a "Real" Uno.
Compile for Clone Pro 3 volt mini the sketch is to big by 1016K.
Some pointers to reduce its size would be great.

cheers
Peter

TFT_2_4___T_H_P copy.ino (8.65 KB)

pretty heavy library as it is not that much code.

  1. you should look for (almost)duplicate code and capture it in a function.

sin((i - 90) * 0.0174532925);
cos((i - 90) * 0.0174532925);
cos((i + seg - 90) * 0.0174532925);
...

can all be calls to

float sineWave(int phase)
{
return sin(phase * 0.0174532925);
}

float cosWave(int phase)
{
return cos(phase * 0.0174532925);
}

  1. replacing float math with integer math helps a bit

int x2 = sx2 * (r - w) + x;

==>

int x2 = int(sx2 * (r - w) ) + x;

replace int by byte where possible

thanks Rob, will give it a try.

Some more options:
Rebootload the Promini as an Uno, get some of the bootloader space back.
Download using a Programmer via the ICSP pins, ditch the bootloader and get that space back.

Code mentions supporting both SPI & I2C for the LCD. Why not clean out the one you're Not using?

You could install the optiboot bootloader on you clone Arduino Pro Mini. That would give you the same memory space as the UNO.

uint32_t runTime = -99999;       // time for next update

Probably shouldn't store a negative number in an unsigned integer.

  mySensor.settings.commInterface = SPI_MODE;
  mySensor.settings.I2CAddress = 0x76;

You can probably get rid of one of these lines.

  (mySensor.begin(), HEX);

You don't need the HEX part of this comma expression. "mySensor.begin();" does the same thing.

The Attached sketch compiles to 31230k

Yeah. Right.