mirror of
https://github.com/jaksatomovic/esp32-clickwheel.git
synced 2025-08-26 22:58:30 -04:00
first commit
This commit is contained in:
commit
868b14f8c8
286 changed files with 59925 additions and 0 deletions
|
@ -0,0 +1,64 @@
|
|||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Button2.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
#define BUTTON_PIN_1 3
|
||||
#define BUTTON_PIN_2 4
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
Button2 button_1, button_2;
|
||||
|
||||
unsigned long now = 0;
|
||||
byte counter = 0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
delay(50);
|
||||
Serial.println("\n\nTrack dual button press & release");
|
||||
|
||||
button_1.begin(BUTTON_PIN_1);
|
||||
button_1.setPressedHandler(pressed);
|
||||
button_1.setReleasedHandler(released);
|
||||
|
||||
button_2.begin(BUTTON_PIN_2);
|
||||
button_2.setPressedHandler(pressed);
|
||||
button_2.setReleasedHandler(released);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void loop() {
|
||||
button_1.loop();
|
||||
button_2.loop();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void pressed(Button2& btn) {
|
||||
counter++;
|
||||
if (counter == 2) {
|
||||
now = millis();
|
||||
Serial.println("now!");
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void released(Button2& btn) {
|
||||
counter--;
|
||||
if (counter == 0) {
|
||||
if (now != 0) {
|
||||
Serial.print("Pressed for: ");
|
||||
Serial.print(millis() - now);
|
||||
Serial.println("ms");
|
||||
}
|
||||
now = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue