File tree 1 file changed +30
-31
lines changed
libraries/esp8266/examples/GPIO/FunctionalInterrupt
1 file changed +30
-31
lines changed Original file line number Diff line number Diff line change 12
12
#define BUTTON2 0
13
13
#endif
14
14
15
- class Button
16
- {
17
- public:
18
- Button (uint8_t reqPin) : PIN(reqPin) {
19
- pinMode (PIN, INPUT_PULLUP);
20
- attachInterrupt (PIN, std::bind (&Button ::isr,this ), FALLING);
21
- };
22
- ~Button () {
23
- detachFunctionalInterrupt (PIN);
24
- }
15
+ class Button {
16
+ public:
17
+ Button (uint8_t reqPin) : PIN(reqPin) {
18
+ pinMode (PIN, INPUT_PULLUP);
19
+ attachInterrupt (PIN, std::bind (&Button ::isr, this ), FALLING);
20
+ };
21
+ ~Button () {
22
+ detachFunctionalInterrupt (PIN);
23
+ }
25
24
26
25
#if defined(ESP8266)
27
- void ICACHE_RAM_ATTR isr ()
26
+ void ICACHE_RAM_ATTR isr ()
28
27
#elif defined(ESP32)
29
- void IRAM_ATTR isr ()
28
+ void IRAM_ATTR isr ()
30
29
#endif
31
- {
32
- numberKeyPresses += 1 ;
33
- pressed = true ;
34
- }
35
-
36
- void checkPressed () {
37
- if (pressed) {
38
- Serial.printf (" Button on pin %u has been pressed %u times\n " , PIN, numberKeyPresses);
39
- pressed = false ;
40
- }
41
- }
42
-
43
- private:
44
- const uint8_t PIN;
45
- volatile uint32_t numberKeyPresses;
46
- volatile bool pressed;
30
+ {
31
+ numberKeyPresses += 1 ;
32
+ pressed = true ;
33
+ }
34
+
35
+ void checkPressed () {
36
+ if (pressed) {
37
+ Serial.printf (" Button on pin %u has been pressed %u times\n " , PIN, numberKeyPresses);
38
+ pressed = false ;
39
+ }
40
+ }
41
+
42
+ private:
43
+ const uint8_t PIN;
44
+ volatile uint32_t numberKeyPresses;
45
+ volatile bool pressed;
47
46
};
48
47
49
48
Button button1 (BUTTON1);
50
49
Button button2 (BUTTON2);
51
50
52
51
53
52
void setup () {
54
- Serial.begin (115200 );
53
+ Serial.begin (115200 );
55
54
}
56
55
57
56
void loop () {
58
- button1.checkPressed ();
59
- button2.checkPressed ();
57
+ button1.checkPressed ();
58
+ button2.checkPressed ();
60
59
}
You can’t perform that action at this time.
0 commit comments