Servo problem...help please

Hi.
My problem is, my servo doesn´t works inside an interruption, when i click on a pushbutton the servo doesns works. I tried to put on void loop and works.
My program is:

#include <Servo.h>
Servo myservo;
int pos = 0;
int counter = 0;
volatile int state = LOW;

void setup() {
pinMode(2, INPUT); // entry
myservo.attach(9);
attachInterrupt(0,entrada,RISING); //pino 2
}
void loop() {

}

void entrada () {
counter++;
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
}

Help please.

Inside an ISR, timers don't update, so delays are a bad idea (really, really bad), and so are servo writes.

"push button" and "interrupt" are not really in the same timescale. Think about polling

polling?what is that?
you can post an example please.

i dont now how to use pollings.... :cold_sweat:

Just keep reading pin 2 until it changes.

dont exists another way to do this using interrupts?
or another another way to control a servo

Why do you think you need to use interrupts?

because this is a little part of my original program, and i need to use interrupts on that program

Perhaps you should give a detailed word discription of what you are trying to accomplish.

I want to make a program that manages the inputs and outputs of the car park, showing that there is empty seats or not. On the entry and the exit there is a servo who works when a button is pressed. Its all working well but the servos not.
There is 2 interruptions (entry and exit).

Interrupts on an AVR work on timescales of tens of nanoseconds.
What sort of carpark work at that sort of timescale?

for that reason i want to know if exist another way to the servo move when the button is pressed without remove the interrupt

without remove the interrupt

Let me put it another way.
The processor checks for interrupts every instruction cycle.
An instruction executes in the time it takes a beam of light to travel 20 metres.
Why do you think an application involving a car park needs to execute on such timescales?
You don't need an interrupt here.