-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushButton.cpp
More file actions
45 lines (42 loc) · 1.12 KB
/
Copy pathPushButton.cpp
File metadata and controls
45 lines (42 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "PushButton.h"
#include <WiFi.h>
/** The code herein written by the Author is released under the terms of the unlicense. https://unlicense.org/
* @author https://github.com/lexfp
*/
void PushButton::init(int pin) {
pushButtonPin = pin;
pinMode(pushButtonPin, INPUT_PULLUP);
lastTimeStamp = esp_log_timestamp();
buttonDown = 0;
}
bool PushButton::checkForClick() {
int Push_button_state = digitalRead(pushButtonPin);
// if condition checks if push button is pressed
if ( Push_button_state != HIGH )
{
uint32_t differenceTimeStamp = esp_log_timestamp() - lastTimeStamp;
if (buttonDown == 0) {
if (differenceTimeStamp > buttonClickTime)
{
//Serial.println("Button Down");
buttonDown = 1;
lastTimeStamp = esp_log_timestamp();
return 1;
}
}
}
else
{
uint32_t differenceTimeStamp = esp_log_timestamp() - lastTimeStamp;
if (buttonDown == 1)
{
if (differenceTimeStamp > buttonClickTime)
{
//Serial.println("Button Up");
buttonDown = 0;
lastTimeStamp = esp_log_timestamp();
}
}
}
return 0;
}