Error compiling code for Attiny85v

I have sucessfully burned the bootloader onto the Attiny85v using the Arduino as an ISP.

When I try to verify my code, i get a compile error message. I was able to compile a simple blink sketch, but this code will not compile for some reason.
This is the code, which has been shortened to 5 arrays instead of 13 due to posting limitations:

long lastTime = 0;
const int RPIN = 0; //9 or Pin 0, physical pin 5
const int GPIN =1;  //11 or Pin 1, physical pin 6
const int BPIN =4; //10 or or Pin 4, physical pin 3
const int SWITCHPIN = 2; //A4 or Pin 2, physical pin 7
const int potPin = 3;  //A3 or Pin 3, physical pin 2
int potVal = 0;

int countArray[] = {150,106,120};
int maxSwitch = 4;
int currentPlace = 0;
int count = 0;
boolean pressed = false;


//150
prog_uchar PROGMEM rArray0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
prog_uchar PROGMEM gArray0[] = {50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,
9,8,7,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50};
prog_uchar PROGMEM bArray0[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
46,47,48,49,50,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  
int hArray0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //25
};


//106
prog_uchar PROGMEM rArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,      
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uchar PROGMEM gArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uchar PROGMEM bArray1[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,    
50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,0,0,0,0};  
int hArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0};



//120
prog_uchar PROGMEM rArray2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uchar PROGMEM gArray2[] = {0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,
20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20,0,20};
prog_uchar PROGMEM bArray2[] = {100,0,98,0,96,0,94,0,92,0,90,0,88,0,86,0,84,0,82,0,80,0,78,0,76,0,74,0,72,0,70,0,68,0,66,0,64,0,62,0,60,0,58,0,56,0,54,0,52,0,    
50,0,48,0,46,0,44,0,42,0,40,0,38,0,36,0,34,0,32,0,30,0,28,0,26,0,24,0,22,0,20,0,18,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,0,0,0,0,0};  
int hArray2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //20

void setup(){
  Serial.begin(9600);
  pinMode(RPIN,OUTPUT);
  pinMode(GPIN,OUTPUT);
  pinMode(BPIN,OUTPUT);
  pinMode(SWITCHPIN,INPUT);
  pinMode(potPin,INPUT);
  }


void checkBtn(){
 boolean switcher = digitalRead(SWITCHPIN);
 if(!pressed && switcher){
  pressed = true;
  currentPlace++;
  count = 0;
  lastTime = millis();
   }

if(pressed && !switcher){
   pressed = false;
 }
}
 checkBtn();

  
  
  if(lastTime == 0){
  lastTime = millis();
  }

    Serial.print(" count:   ");
    Serial.print(count);
    Serial.print(" potVal: ");
    Serial.println(hArray0[count] + potVal/4);


//////
  if(lastTime + hArray0[count] + potVal/4 < millis() && currentPlace == 0){  
 
   analogWrite(RPIN,pgm_read_byte(&(rArray0[count])));
   analogWrite(GPIN,pgm_read_byte(&(gArray0[count])));
   analogWrite(BPIN,pgm_read_byte(&(bArray0[count])));
   lastTime = millis();
   count = count + 1;
   if(count >= countArray[currentPlace]){
    count = 0; 
   }
 }
 ///////
  if(lastTime + hArray1[count] + potVal/4 < millis() && currentPlace == 1){   
  analogWrite(RPIN,pgm_read_byte(&(rArray1[count])));
  analogWrite(GPIN,pgm_read_byte(&(gArray1[count])));
  analogWrite(BPIN,pgm_read_byte(&(bArray1[count])));
   lastTime = millis();
   count = count + 1;
   if(count >= countArray[currentPlace]){
    count = 0; 
   }
 }
//////
  if(lastTime + hArray2[count] + potVal/4 < millis() && currentPlace == 2){   
   analogWrite(RPIN,pgm_read_byte(&(rArray2[count])));
   analogWrite(GPIN,pgm_read_byte(&(gArray2[count])));
   analogWrite(BPIN,pgm_read_byte(&(bArray2[count])));
   lastTime = millis();
   count = count + 1;
   if(count >= countArray[currentPlace]){
    count = 0; 
   }
 }
    if(currentPlace >= maxSwitch){
   currentPlace = 0;
  } 
 }

Any idea what might be going wrong?

thank you so much for your help!

And this is the Error Compiling message:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4' defined in .text.__vector_4 section in core.a(wiring.c.o)
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)
FINAL_ARRAYS.cpp.o: In function `loop':
FINAL_ARRAYS.cpp:250: relocation truncated to fit: R_AVR_13_PCREL against symbol `__divmodhi4' defined in .text.libgcc section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_divmodhi4.o)
FINAL_ARRAYS.cpp:257: relocation truncated to fit: R_AVR_13_PCREL against symbol `__divmodhi4' defined in .text.libgcc section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_divmodhi4.o)

Any idea what might be going wrong?

thank you so much for your help!

Can you post the code which is at lines 250 and 257 in your program, since you have deleted some, we can't
tell where that is.
The error message appears to be telling you, that is where the problem is. ( sometimes it's wrong, but that is
still where you need to start looking ).

My guess is that it is too large.

I went back and disabled the serial.begin(9600) and all of the corresponding serial.print
The only code that was deleted was more arrays, the original code has about 12 different array patterns.
When I tried to compile that code, this was the error readout:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o: In function `__vector_default':
(.vectors+0x8): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_4' defined in .text.__vector_4 section in core.a(wiring.c.o)

Out of curiosity, I tried to compile a shorter version of the code similar to what I posted, and it was able to compile. Maybe it is an issue with the size? that's why I had the code set up so that the arrays were stored in the PROGMEM, in hopes that it would clear up the size of the sketch.

It's a bug in the linker. I'll be back with some solutions...

coding badly hopefully saves the day once again :slight_smile:
I'm in the midst of trying to pull an late night @ the Dallas Makerspace to try and finish up some projects involving this code.

One of these should get you past the problem...

I'm on a Mac. could open this with an emulator but not sure if it'll be an issue

The only help I can provide for a Mac is from the first post...

This fixed the compiling error. I was able to upload it successfully. Nothing appears to be happening when the circuit is wired up though...none of the LED's light up for the RPIN,GPIN,or BPIN.

It's bedtime. Hopefully someone else (those friendly Europeans are waking / awake) will lend a hand until I'm back.

If I insert:

 void loop(){

Just above
checkBtn();

Your sketch compiles and the LED's blink.

Hope this helps.

Ill try that out and see if it helps! Thank you for playing aroun with the code...I was wondering if it was still too large of a sketch to compile onto such a small IC...I thought that utilizing the PROGMEM for storage would free up enough space.

I also wondered what differences there may need to be changed to make the code compatible with the attiny besides the pinouts.

void loop(){
  potVal = analogRead(potPin);
  checkBtn();
  
  if(lastTime == 0){
  lastTime = millis();
  }

I checked the code, and in the code i quoted in the first post, I had accidentally deleted the void loop() that was necessary, but the code listed here is what is actually in the sketch. sorry for the confusion.
the code works great on the arduino board with the atmega328, but it does not work on the attiny, even when the code has been shortened

long lastTime = 0;
const int RPIN = 0; //9 or Pin 0, physical pin 5
const int GPIN =1;  //11 or Pin 1, physical pin 6
const int BPIN =4; //10 or or Pin 4, physical pin 3
const int SWITCHPIN = 2; //A4 or Pin 2, physical pin 7
const int potPin = 3;  //A3 or Pin 3, physical pin 2
int potVal = 0;

int countArray[] = {150,106};
int maxSwitch = 3;
int currentPlace = 0;
int count = 0;
boolean pressed = false;


//150
prog_uchar PROGMEM rArray0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};
prog_uchar PROGMEM gArray0[] = {50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,
9,8,7,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50};
prog_uchar PROGMEM bArray0[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
46,47,48,49,50,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  
int hArray0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //25
};


//106
prog_uchar PROGMEM rArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,      
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uchar PROGMEM gArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
prog_uchar PROGMEM bArray1[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,    
50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,0,0,0,0};  
int hArray1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
0,0,0,0,0,0};



void setup(){
//  Serial.begin(9600);
  pinMode(RPIN,OUTPUT);
  pinMode(GPIN,OUTPUT);
  pinMode(BPIN,OUTPUT);
  pinMode(SWITCHPIN,INPUT);
  pinMode(potPin,INPUT);
  }


void checkBtn(){
 boolean switcher = digitalRead(SWITCHPIN);
 if(!pressed && switcher){
  pressed = true;
  currentPlace++;
  count = 0;
  lastTime = millis();
   }

if(pressed && !switcher){
   pressed = false;
 }
}


void loop(){
  potVal = analogRead(potPin);
  checkBtn();
  
  if(lastTime == 0){
  lastTime = millis();
  }
 
 
  if(lastTime + hArray0[count] + potVal/4 < millis() && currentPlace == 0){  
   analogWrite(RPIN,pgm_read_byte(&(rArray0[count])));
   analogWrite(GPIN,pgm_read_byte(&(gArray0[count])));
   analogWrite(BPIN,pgm_read_byte(&(bArray0[count])));
   lastTime = millis();
   count = count + 1;
   if(count >= countArray[currentPlace]){
    count = 0; 
   }
 }
 //////////////////////////
  if(lastTime + hArray1[count] + potVal/4 < millis() && currentPlace == 1){   
  analogWrite(RPIN,pgm_read_byte(&(rArray1[count])));
  analogWrite(GPIN,pgm_read_byte(&(gArray1[count])));
  analogWrite(BPIN,pgm_read_byte(&(bArray1[count])));
   lastTime = millis();
   count = count + 1;
   if(count >= countArray[currentPlace]){
    count = 0; 
   }
 }
 
    if(currentPlace >= maxSwitch){
   currentPlace = 0;
  } 
 
 }

Here is another copy of the code, exactly what i have tried to upload to the attiny. I have burned the bootloader and uploaded the code to the attiny at 16 MHz, 8 MHz, and 1 MHz, none of which work. I have no idea what else to do at this point.

int hArray0[] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //25
};
...
int hArray1[] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  //25
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //25
  0,0,0,0,0,0};

If my arithmetic is correct those two arrays take up 512 bytes of SRAM.

 (6 * 25 + 106) * 2 = 512

The Attiny85 only has 512 bytes of SRAM and you have other variables:

int potVal = 0;

int countArray[] = {
  150,106};
int maxSwitch = 3;
int currentPlace = 0;
int count = 0;
boolean pressed = false;

And you need some room for the generated code's work data.