Reduce Size of Code

Hi All,
The code below sites at > 33k works OK on a Mega,
Using the large fonts makes go over the 32K limit.
Want to run on a UNO.
How can I reduce the code futher?
Can I strip out parts of the Ucglib???
Only go to use this display Ucglib_ST7735_18x128x160_SWSPI ucg

Cheers
Peter

//SAT_May_31_2014
#include "I2Cdev.h"
#include <SPI.h>
#include "Ucglib.h"

Ucglib_ST7735_18x128x160_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9 , /*cs=*/ 10, /*reset=*/ 8);

#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
MPU6050 mpu;
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
int Pitch;
int Roll;
int Pitch_Down;
int Pitch_Up;
int Roll_L;
int Roll_R;
const int buttonPin  = 3;     // the number of the pushbutton pin
int buttonState      = 0;
int led              = 12;
// ================================================================
// ===               INTERRUPT DETECTION ROUTINE                ===
// ================================================================

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
  mpuInterrupt = true;
}



// ================================================================
// ===                      INITIAL SETUP                       ===
// ================================================================

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(led, OUTPUT);

  ucg.begin(UCG_FONT_MODE_SOLID);

  ucg.clearScreen();
  ucg.setRotate90();
  ucg.setFont(ucg_font_fur25r);
  ucg.setPrintPos(2, 36);
  ucg.print("Roll");
  ucg.setPrintPos(2, 98);
  ucg.print("Pitch");

  ucg.setColor(0, 100, 100);
  ucg.setFont(ucg_font_7x14);
  ucg.setPrintPos(2, 120);
  ucg.print("Down");
  ucg.setPrintPos(84, 120);
  ucg.print("Up-");
  ucg.setPrintPos(2, 56);
  ucg.print("Left-");
  ucg.setPrintPos(84, 56);
  ucg.print("Right-");

  mpu.initialize();

  devStatus = mpu.dmpInitialize();

  // supply your own gyro offsets here, scaled for min sensitivity
  mpu.setXGyroOffset(220);
  mpu.setYGyroOffset(76);
  mpu.setZGyroOffset(-85);
  mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

  // make sure it worked (returns 0 if so)
  if (devStatus == 0) {
    // turn on the DMP, now that it's ready
    //Serial.println(F("Enabling DMP..."));
    mpu.setDMPEnabled(true);

    // enable Arduino interrupt detection
    //Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
    attachInterrupt(0, dmpDataReady, RISING);
    mpuIntStatus = mpu.getIntStatus();

    // set our DMP Ready flag so the main loop() function knows it's okay to use it
    //Serial.println(F("DMP ready! Waiting for first interrupt..."));
    dmpReady = true;

    // get expected DMP packet size for later comparison
    packetSize = mpu.dmpGetFIFOPacketSize();
  } else {

  }
}

// ================================================================
// ===                    MAIN PROGRAM LOOP                     ===
// ================================================================

void loop() {

  // if programming failed, don't try to do anything
  if (!dmpReady) return;

  // wait for MPU interrupt or extra packet(s) available
  while (!mpuInterrupt && fifoCount < packetSize) {

  }

  // reset interrupt flag and get INT_STATUS byte
  mpuInterrupt = false;
  mpuIntStatus = mpu.getIntStatus();



  // get current FIFO count
  fifoCount = mpu.getFIFOCount();

  // check for overflow (this should never happen unless our code is too inefficient)
  if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    // Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
  } else if (mpuIntStatus & 0x02) {
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

    // read a packet from FIFO
    mpu.getFIFOBytes(fifoBuffer, packetSize);

    // track FIFO count here in case there is > 1 packet available
    // (this lets us immediately read more without waiting for an interrupt)
    fifoCount -= packetSize;
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);    

    
    Roll = ypr[1] * 180 / M_PI, 0;
    Pitch = ypr[2] * 180 / M_PI, 0;
    
    ucg.setColor(0, 100, 100);
    ucg.setFont(ucg_font_7x14);
    
    if (Roll > Roll_L) {
      Roll_L = Roll;
      ucg.setPrintPos(44, 56);
      ucg.print(Roll_L);
    }
    if (Roll < Roll_R) {
      Roll_R = Roll;
      ucg.setPrintPos(120, 56);
      ucg.print(Roll_R);
    }
    
    if (Pitch < Pitch_Down) {
      Pitch_Down = Pitch;
      ucg.setPrintPos(44, 120);
      ucg.print(Pitch_Down);
    }

    if (Pitch > Pitch_Up) {
      Pitch_Up = Pitch;
      ucg.setPrintPos(120, 120);
      ucg.print(Pitch_Up);
    }
       
    ucg.setColor(0, 255, 0);
    ucg.setFont(ucg_font_fur25r);
    ucg.setPrintPos(92, 36);
    if (Roll < 0) Roll = Roll * -1;
    if (Roll > 35) ucg.setColor(255, 0, 0);
    if (Roll < 10) ucg.print("0");
    ucg.print(Roll);
    
    ucg.setColor(0, 255, 0);
    ucg.setPrintPos(92, 98);
    ucg.setFont(ucg_font_fur25r);
    if (Pitch < 0) Pitch = Pitch * -1;
    if (Pitch > 35) ucg.setColor(255, 0, 0);
    if (Pitch < 10) ucg.print("0");
    ucg.print(Pitch);

  }
}

how much bytes do you go over the limit ?

You might have a go at refactoring your yaw/pitch/roll calculations into fixed point. This would possibly eliminate the float library requirements.

Current Size 33,864

Yaw/Pitch/Roll code.. That part of the code was from the sample sketch, not by me :) Some help here would be great

Reduce the number/size of the fonts you are using or sptip out the chars you don't use from the fonts.

Mark