ESP_IOT
v2.5
IOT ESP Coding
ButtonModule.cpp
Go to the documentation of this file.
1
/**
2
* \link ButtonModule
3
*/
4
/*
5
*******************************************************************************
6
// https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
7
8
Enable (EN)
9
Enable (EN) is the 3.3V regulator␖â␖s enable pin. It␖â␖s pulled up, so connect to ground to disable the 3.3V regulator. This means that you can use this pin connected to a pushbutton to restart your ESP32, for example.
10
11
Scott Version: 1.1.2022
12
*******************************************************************************
13
*/
14
#include "
ButtonModule.h
"
15
16
#ifdef USE_BUTTON_MODULE
17
18
//extension of ButtonModule - includes Sensors
19
#include "
ButtonProcessing.h
"
20
21
22
//#define ESP_M5
23
#ifdef ESP_M5
24
#include <M5StickCPlus.h>
25
#else
26
#include <Arduino.h>
27
#endif
28
29
//! called by the feed operation to say the device is still running.. and count it as a button click.
30
void
refreshDelayButtonTouched_ButtonModule
()
31
{
32
refreshDelayButtonTouched_ButtonProcessing
();
33
}
34
35
// See https://forum.arduino.cc/t/arduino-push-button-double-click-function/409353
36
37
// set PushButton pin number
38
const
int
_buttonPin
= 0;
39
40
// set LED pin numbers
41
const
int
GPIO0
=
_buttonPin
;
42
43
const
int
LED1
= 8;
44
const
int
LED2
= 9;
45
46
// set LED pin 13
47
const
int
LEDP13
= 13;
48
49
//initialising led
50
int
LED1Status
= LOW;
51
int
LED2Status
= LOW;
52
53
int
_buttonState
;
54
55
//state of the button..
56
boolean
_buttonPressed
;
57
58
void
setup_ButtonModule
()
59
{
60
61
// put your setup code here, to run once:
62
_buttonPressed
=
false
;
63
64
#ifdef ESP_32
65
// initialize the LED pin as an output:
66
pinMode(
_buttonPin
,INPUT);
67
#endif
68
//!calls the extension of ButtonModule
69
setup_ButtonProcessing
();
70
71
}
72
//if _buttonPressed (the LOW state == 0)
73
// then wait for the HIGH state == 1
74
// and that is a button click..
75
76
void
loop_ButtonModule
()
77
{
78
79
#ifdef ESP_32
80
// put your main code here, to run repeatedly:
81
82
_buttonState
= digitalRead(
_buttonPin
);
83
switch
(
_buttonState
)
84
{
85
case
LOW:
//0
86
_buttonPressed
=
true
;
87
break
;
88
default
:
89
90
case
HIGH:
// 1 (nothing touched)
91
if
(
_buttonPressed
)
92
{
93
// then the button was unpressed..
94
SerialLots.println(
"BUTTON PRESSED and RELEASED"
);
95
_buttonPressed
=
false
;
96
97
callCallbackMain
(
CALLBACKS_BUTTON_MODULE
,
SINGLE_CLICK_BM
, (
char
*)
"B1"
);
98
99
}
100
break
;
101
}
102
//SerialLots.printf("_buttonState = %d\n", _buttonState);
103
#endif
104
//!calls the extension of ButtonModule
105
loop_ButtonProcessing
();
106
}
107
108
//!This is only thing exposed to others.. (Kinda which only 1 button module)
109
//!short press on buttonA (top button)
110
void
buttonA_ShortPress_ButtonModule
()
111
{
112
buttonA_ShortPress
();
113
}
114
//!long press on buttonA (top button)
115
void
buttonA_LongPress_ButtonModule
()
116
{
117
buttonA_LongPress
();
118
}
119
//!the long press of the side button
120
void
buttonB_LongPress_ButtonModule
()
121
{
122
buttonB_LongPress
();
123
}
124
//!the short press of the side button
125
void
buttonB_ShortPress_ButtonModule
()
126
{
127
buttonB_ShortPress
();
128
}
129
130
#endif
//USE_BUTTON_MODULE
LED2
const int LED2
Definition:
ButtonModule.cpp:44
LEDP13
const int LEDP13
Definition:
ButtonModule.cpp:47
GPIO0
const int GPIO0
Definition:
ButtonModule.cpp:41
LED2Status
int LED2Status
Definition:
ButtonModule.cpp:51
buttonB_ShortPress_ButtonModule
void buttonB_ShortPress_ButtonModule()
the short press of the side button
Definition:
ButtonModule.cpp:125
buttonB_LongPress_ButtonModule
void buttonB_LongPress_ButtonModule()
the long press of the side button
Definition:
ButtonModule.cpp:120
loop_ButtonModule
void loop_ButtonModule()
Definition:
ButtonModule.cpp:76
LED1
const int LED1
Definition:
ButtonModule.cpp:43
_buttonPressed
boolean _buttonPressed
Definition:
ButtonModule.cpp:56
_buttonPin
const int _buttonPin
Definition:
ButtonModule.cpp:38
buttonA_ShortPress_ButtonModule
void buttonA_ShortPress_ButtonModule()
Definition:
ButtonModule.cpp:110
refreshDelayButtonTouched_ButtonModule
void refreshDelayButtonTouched_ButtonModule()
called by the feed operation to say the device is still running.. and count it as a button click.
Definition:
ButtonModule.cpp:30
buttonA_LongPress_ButtonModule
void buttonA_LongPress_ButtonModule()
long press on buttonA (top button)
Definition:
ButtonModule.cpp:115
setup_ButtonModule
void setup_ButtonModule()
Definition:
ButtonModule.cpp:58
LED1Status
int LED1Status
Definition:
ButtonModule.cpp:50
_buttonState
int _buttonState
Definition:
ButtonModule.cpp:53
ButtonModule.h
SINGLE_CLICK_BM
#define SINGLE_CLICK_BM
Definition:
ButtonModule.h:24
loop_ButtonProcessing
void loop_ButtonProcessing()
the loop for buttonProcessing (extension of ButtonModule)
Definition:
ButtonProcessing.cpp:857
buttonB_ShortPress
void buttonB_ShortPress()
the short press of the side button
Definition:
ButtonProcessing.cpp:631
refreshDelayButtonTouched_ButtonProcessing
void refreshDelayButtonTouched_ButtonProcessing()
called by the feed operation to say the device is still running.. and count it as a button click.
Definition:
ButtonProcessing.cpp:145
setup_ButtonProcessing
void setup_ButtonProcessing()
Definition:
ButtonProcessing.cpp:830
buttonA_LongPress
void buttonA_LongPress()
defines M5 info: https://docs.rs-online.com/e4eb/A700000008182827.pdf
Definition:
ButtonProcessing.cpp:503
buttonB_LongPress
void buttonB_LongPress()
the long press of the side button
Definition:
ButtonProcessing.cpp:592
buttonA_ShortPress
void buttonA_ShortPress()
short press on buttonA (top button)
Definition:
ButtonProcessing.cpp:516
ButtonProcessing.h
callCallbackMain
void callCallbackMain(int callbacksModuleId, int callbackType, char *message)
performs the indirect callback based on the callbackType
Definition:
MainModule.cpp:333
CALLBACKS_BUTTON_MODULE
#define CALLBACKS_BUTTON_MODULE
Definition:
MainModule.cpp:222
src
ButtonModule
ButtonModule.cpp
Generated on Wed Jan 11 2023 09:16:22 for ESP_IOT by
1.9.5