long short press arduino
#define PIN_TL 2
#define CAS_ZAKMITU 10
volatile unsigned long posledniZmenaTl = 0;
volatile bool posledniStavTl = HIGH;
volatile unsigned long posledniStiskTl = 0;
volatile unsigned long dobaStisku = 0;
void setup() {
pinMode(PIN_TL, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_TL), zmenaTlacitka, CHANGE);
Serial.begin(9600);
}
void loop() {
if (dobaStisku > 0) {
if (dobaStisku < 400) {
Serial.println("kratky stisk");
} else {
Serial.println("dlouhy stisk");
}
dobaStisku = 0;
}
}
void zmenaTlacitka() {
if (millis() >= posledniZmenaTl + CAS_ZAKMITU && digitalRead(PIN_TL) != posledniStavTl) {
posledniZmenaTl = millis();
posledniStavTl = !posledniStavTl;
//Serial.println(posledniStavTl);
if (posledniStavTl == LOW) {
posledniStiskTl = millis();
} else {
dobaStisku = millis() - posledniStiskTl;
}
}
}