ATmega2560 sketch size bug...

Hello guys, i was recently trying to upload this code to my arduino :

const uint8_t switchesPins[] = { 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; // Defenição dos pinos

uint8_t a = 1; // Defenição das variaveis
uint8_t b = 1;
uint8_t c = 1;
uint8_t d = 1;
uint8_t e = 1;
uint8_t f = 1;
uint8_t g = 1;
uint8_t h = 1;
uint8_t i = 1;
uint8_t j = 1;
uint8_t k = 1;
uint8_t l = 1;
uint8_t m = 1;
uint8_t n = 1;
uint8_t o = 1;
uint8_t p = 1;
uint8_t q = 1;
uint8_t r = 1;

void setup()
{
 Serial.begin( 9600 ); // Manda o arduino comunicar com o módulo bluetooth

 for ( uint8_t i = 0; i < sizeof( switchesPins ); i++ )
 {
   pinMode( switchesPins[i], OUTPUT ); // Define todos os pinos como Outputs
   digitalWrite( switchesPins[i], HIGH ); // Define que todos os pinos começam na posição 1
 }
}

void loop()
{
 if ( Serial.available() ) // Se ouver dados provenientes do modulo bluetooth...
 {


   switch ( Serial.read() ) // Então o arduino lê esses dados
   {
     case 'a' :
       if (a == 0) {
         //Botao 0 está na posição 1 vamos desligar...
         digitalWrite( switchesPins[0], HIGH );
         a = 1; // Pino 22 está a 1 logo o equipamento desliga
       } else {
         //botao 0 está na posição 0 vamos ligar...
         digitalWrite( switchesPins[0], LOW );
         a = 0; // Pino 22 vai a 0 logo o equipamento liga
       }
       break; // Nova instrução

     case 'b' :
       if (b == 0) {

         digitalWrite( switchesPins[1], HIGH );
         b = 1;
       } else {

         digitalWrite( switchesPins[1], LOW );
         b = 0;
       }
       break;

     case 'c' :
       if (c == 0) {

         digitalWrite( switchesPins[2], HIGH );
         c = 1;
       } else {

         digitalWrite( switchesPins[2], LOW );
         c = 0;
       }
       break;

     case 'd' :
       if (d == 0) {

         digitalWrite( switchesPins[3], HIGH );
         d = 1;
       } else {

         digitalWrite( switchesPins[3], LOW );
         d = 0;
       }
       break;

     case 'e' :
       if (e == 0) {

         digitalWrite( switchesPins[4], HIGH );
         e = 1;
       } else {

         digitalWrite( switchesPins[4], LOW );
         e = 0;
       }
       break;

     case 'f' :
       if (f == 0) {

         digitalWrite( switchesPins[5], HIGH );
         f = 1;
       } else {

         digitalWrite( switchesPins[5], LOW );
         f = 0;
       }
       break;

     case 'g' :
       if (g == 0) {

         digitalWrite( switchesPins[6], HIGH );
         g = 1;
       } else {

         digitalWrite( switchesPins[6], LOW );
         g = 0;
       }
       break;

     case 'h' :
       if (h == 0) {

         digitalWrite( switchesPins[7], HIGH );
         h = 1;
       } else {

         digitalWrite( switchesPins[7], LOW );
         h = 0;
       }
       break;

     case 'i' :
       if (i == 0) {

         digitalWrite( switchesPins[8], HIGH );
         i = 1;
       } else {

         digitalWrite( switchesPins[8], LOW );
         i = 0;
       }
       break;

     case 'j' :
       if (j == 0) {

         digitalWrite( switchesPins[9], HIGH );
         j = 1;
       } else {

         digitalWrite( switchesPins[9], LOW );
         j = 0;
       }
       break;

     case 'k' :
       if (k == 0) {

         digitalWrite( switchesPins[10], HIGH );
         k = 1;
       } else {

         digitalWrite( switchesPins[10], LOW );
         k = 0;
       }
       break;

     case 'l' :
       if (l == 0) {

         digitalWrite( switchesPins[11], HIGH );
         l = 1;
       } else {

         digitalWrite( switchesPins[11], LOW );
         l = 0;
       }
       break;

     case 'm' :
       if (m == 0) {

         digitalWrite( switchesPins[12], HIGH );
         m = 1;
       } else {

         digitalWrite( switchesPins[12], LOW );
         m = 0;
       }
       break;

     case 'n' :
       if (n == 0) {

         digitalWrite( switchesPins[13], HIGH );
         n = 1;
       } else {

         digitalWrite( switchesPins[13], LOW );
         n = 0;
       }
       break;

     case 'o' :
       if (o == 0) {

         digitalWrite( switchesPins[14], HIGH );
         o = 1;
       } else {

         digitalWrite( switchesPins[14], LOW );
         o = 0;
       }
       break;

     case 'p' :
       if (p == 0) {

         digitalWrite( switchesPins[15], HIGH );
         p = 1;
       } else {

         digitalWrite( switchesPins[15], LOW );
         p = 0;
       }
       break;

     case 'q' :
       if (q == 0) {

         digitalWrite( switchesPins[16], HIGH );
         q = 1;
       } else {

         digitalWrite( switchesPins[16], LOW );
         q = 0;
       }
       break;

     case 'r' :
       if (r == 0) {

         digitalWrite( switchesPins[17], HIGH );
         r = 1;
       } else {

         digitalWrite( switchesPins[17], LOW );
         r = 0;
       }
       break;
   }
 }
}

The code compiles without a problem, but when i try to upload it to the arduino, i get this message :

Sketch uses 3,062 bytes (1%) of program storage space. Maximum is 253,952 bytes.
Global variables use 218 bytes (2%) of dynamic memory, leaving 7,974 bytes for local variables. Maximum is 8,192 bytes.
An error occurred while uploading the sketch

I’ve tryed to change the code, and even upload simple codes like the blink one, and i always get the same message.
Some things i find strange is that, when i connect my board to the PC the power LED and the PWM LED are always on! And on my port settings, on the arduino tools menu, my atmega is epresented has arduino uno… No idea why…
This arduino has been running for over 2 years 24/7 on a project i did, and now i took it off to update the code.
I would apreciate if you could help me, thank you in advance.

Are you using Arduino IDE 1.6.10?

Please use code tags(</> button on the toolbar) whenever you post code or error/warning messages on the forum. If you look at the code you posted, you’ll see that some of the text disappeared and most of the code is in italics. This is because the forum software mistook some of the text for forum markup([ i ] means italics). If you had used code tags that wouldn’t have happened

Im sorry i completely forgot to format the code. Im actually really noob at arduino, i dont know if im using IDE 1.6.10, i've downloaded arduino software today to upgrade my code. I downloaded it from the official website. How can i check if im missing something?

The IDE version number is displayed at the top of the IDE window. You can also see it at the top left corner of the Help > About Arduino window.

Since you downloaded the IDE today I'm going to assume it's the latest version, 1.6.10. This IDE version has a bug that can cause the error you encountered if you started the IDE by opening a sketch(.ino) file(double clicking on it, etc.) Try this:

  • Close all Arduino IDE windows.
  • Start the Arduino IDE application itself, not by opening a sketch.
  • Open your sketch via File > Open or File > Sketchbook
  • Try uploading
  • Keep your fingers crossed for success!

Ok, so i can confirm the ide version is 1.6.10.
I tried has you saied, and opened the arduino program by itself, altough it automaticly loaded my program, i tried to close/quit the program and restart fresh, but it always loads my project code…
Anyway, i still tried to upload the code to the arduino itself, and now it was uploading for about 1 minute ( and the PWM led was always blinking) and then it gave me the same error again. Even after the error ocurred, the PWM LED never stopped blinking untill i shut off the arduino.

Well, after 10 tryes the program uploaded... Thank you for everything.