Skip to content

Commit b5fd397

Browse files
committed
The rising edge detection was reporting continuously as long as the user is pressing, I fixed that with the addition of the 'rised' flag
1 parent afe2b9c commit b5fd397

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/MyButton.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ bool MyButton :: readRisingClick(){
111111
if(digitalRead(button_pin) == (1 - off_state)){
112112
time_since_clicked = millis();
113113
btn_state = WAIT_BTN;
114+
rised = 1;
114115
}
115116
break;
116117
case WAIT_BTN:
117118
if(digitalRead(button_pin) == off_state){
118119
btn_state = READ_BTN;
119120
}
120-
else if(millis() - time_since_clicked >= debounce_time){
121+
else if((millis() - time_since_clicked >= debounce_time) && rised){
122+
rised = 0;
121123
return true;
122124
}
123125
break;

src/MyButton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
uint8_t btn_state_multiple; // State of the button in the multiple behaviors function
5454
unsigned long time_since_clicked; // Keeps track of the timings
5555
uint32_t timed_read; // To hold the timed read time in microseconds
56+
uint8_t rised; // This flag is used to only send the "rised" detection
5657

5758
/* Button parameters */
5859
uint8_t button_pin;

0 commit comments

Comments
 (0)