Key.readEvent()
Used to detect the [long press] and [short press] actions of digital switches, analog switches and virtual switches. Digital switches: Key. readEvent(time) Description Identify digital sensors’ [long press] and [short press] actions. Digital sensors must be used together with DigitalKey() structure. Parameter
Return uint8_t type. Short press: Analog switch: Key. readEvent(MIN,MAX,time) Description Identify analog sensors’ [long press] and [short press] within corresponding sections. Analog switches must be used together with the structure AnalogKey(). Parameters
Return uint8_t type. Short press: Virtual switch: Key. readEvent(bool,time) Description Identify the [long press] and [short press] actions of analog switches’ corresponding states. Virtual switches must be used together with structure VirtualKey(). Parameters
Return uint8_t type. Short press: Sample
#include <Microduino_Key.h>
AnalogKey keyAnalog(A0);
void setup() {
Serial.begin(9600);
keyAnalog.begin(INPUT);
}
void loop() {
switch (keyAnalog.readEvent(0, 50)) { //(analog minimum, analog maximum)
case SHORT_PRESS:
Serial.println("KEY (analog) SHORT_PRESS"); //Short press
break;
case LONG_PRESS:
Serial.println("KEY (analog) LONG_PRESS"); //Long press
break;
}
delay(50);
}
#include <Microduino_Key.h>
DigitalKey keyDigital(A0);
void setup() {
Serial.begin(9600);
keyDigital.begin(INPUT_PULLUP);
}
void loop() {
switch (keyDigital.readEvent()) {
case SHORT_PRESS:
Serial.println("KEY (digital) SHORT_PRESS"); //Short press
break;
case LONG_PRESS:
Serial.println("KEY (digital) LONG_PRESS"); //Long press
break;
}
delay(50);
}
#include <Microduino_Key.h>
VirtualKey keyVirtual;
void setup() {
Serial.begin(9600);
keyVirtual.begin();
pinMode(A0, INPUT_PULLUP);
}
void loop() {
bool val = !digitalRead(A0); //val any bool variables
switch (keyVirtual.readEvent(val,1500)) { //(a variable, the time of long press) the unit of the time is ms, and the default is 1000
case SHORT_PRESS:
Serial.println("KEY (Virtual) SHORT_PRESS"); //Short press
break;
case LONG_PRESS:
Serial.println("KEY (Virtual) LONG_PRESS"); //Long press
break;
}
delay(50);
} Others |