-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchbutton.cpp
More file actions
39 lines (32 loc) · 1.03 KB
/
touchbutton.cpp
File metadata and controls
39 lines (32 loc) · 1.03 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
#include "touchbutton.h"
#include <Arduino.h>
void isr(void* param)
{
struct Button *button = (struct Button*) param;
button->button_time =millis();
if (((button->button_time) - (button->last_button_time)) > BOUNCE_TIME)
{
button->numberKeyPresses += 1;
button->pressed = 1;
button->last_button_time = button->button_time;
}
}
void checkPressed(struct Button* button)
{
if(button->pressed) {
Serial.printf("Button on pin %u has been pressed %u times\n", button->PIN, button->numberKeyPresses);
button->pressed = 0;
}
}
;
void setup_buttons()
{
pinMode(button1.PIN, INPUT_PULLUP);
pinMode(button2.PIN, INPUT_PULLUP);
pinMode(button3.PIN, INPUT_PULLUP);
pinMode(button4.PIN, INPUT_PULLUP);
attachInterruptArg(button1.PIN, isr, (void*)&button1, FALLING);
attachInterruptArg(button2.PIN, isr, (void*)&button2, FALLING);
attachInterruptArg(button3.PIN, isr, (void*)&button1, FALLING);
attachInterruptArg(button4.PIN, isr, (void*)&button2, FALLING);
}