初始化提交
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Button2.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
#define BUTTON_PIN 2
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
Button2 button = Button2(BUTTON_PIN);
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
delay(20);
|
||||
}
|
||||
Serial.println("\n\nLongpress Handler Demo");
|
||||
|
||||
button.setLongClickHandler(longpress);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void loop() {
|
||||
button.loop();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void longpress(Button2& btn) {
|
||||
unsigned int time = btn.wasPressedFor();
|
||||
Serial.print("You clicked ");
|
||||
if (time > 1500) {
|
||||
Serial.print("a really really long time.");
|
||||
} else if (time > 1000) {
|
||||
Serial.print("a really long time.");
|
||||
} else if (time > 500) {
|
||||
Serial.print("a long time.");
|
||||
} else {
|
||||
Serial.print("long.");
|
||||
}
|
||||
Serial.print(" (");
|
||||
Serial.print(time);
|
||||
Serial.println(" ms)");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
Reference in New Issue
Block a user