Double- and tripple clicking with buttom

Original Post:

By clicking tree times on the buttom the LED is turned on and clicking another two times shoud turn it off.

Try this:

Dowload this library

The sketch:

#define KEY_PIN 7
#define LED_PIN 13
#define REACTION_TIME 500

#include "SwitchPack.h"
DoubleClick key(KEY_PIN, PULLDOWN, REACTION_TIME);


//setup==========
void setup() {
  key.begin();
  key.setMaxClicks(3);
  pinMode(LED_PIN, OUTPUT);
}

//loop=======================
void loop(){
  if (key.clickCount() == 3)  digitalWrite(LED_PIN, HIGH);
  if (key.clickCount() == 2)  digitalWrite(LED_PIN, LOW);
}

P.S. Yes, the switch is debounced.