Dont reply to this

int ledpin=11;
int btnpin=2;
volatile int state = LOW;

void setup()
{                
  pinMode(ledpin, OUTPUT);
  attachInterrupt(0, stateChange, FALLING);
}
void loop()                     
{
  digitalWrite(ledpin, state); 
}
void stateChange()
{
  if(digitalRead(btnpin)==LOW)
  { 
   
      delayMicroseconds(10000);
      if(digitalRead(btnpin)==LOW)
      {
          state = !state;
      }
   }
}

Please give me a good reason not to delete this topic

2 Likes

Might want to add...

  pinMode(btnpin, INPUT_PULLUP);

... and remove...

    // delayMicroseconds(10000);