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)
9Enable (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.
31{
33}
34
35// See https://forum.arduino.cc/t/arduino-push-button-double-click-function/409353
36
37// set PushButton pin number
38const int _buttonPin = 0;
39
40// set LED pin numbers
41const int GPIO0 = _buttonPin;
42
43const int LED1 = 8;
44const int LED2 = 9;
45
46// set LED pin 13
47const int LEDP13 = 13;
48
49//initialising led
50int LED1Status = LOW;
51int LED2Status = LOW;
52
54
55//state of the button..
57
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
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
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)
92 {
93 // then the button was unpressed..
94 SerialLots.println("BUTTON PRESSED and RELEASED");
95 _buttonPressed = false;
96
98
99 }
100 break;
101 }
102 //SerialLots.printf("_buttonState = %d\n", _buttonState);
103#endif
104 //!calls the extension of ButtonModule
106}
107
108//!This is only thing exposed to others.. (Kinda which only 1 button module)
109//!short press on buttonA (top button)
111{
113}
114//!long press on buttonA (top button)
116{
118}
119//!the long press of the side button
121{
123}
124//!the short press of the side button
126{
128}
129
130#endif //USE_BUTTON_MODULE
const int LED2
const int LEDP13
const int GPIO0
int LED2Status
void buttonB_ShortPress_ButtonModule()
the short press of the side button
void buttonB_LongPress_ButtonModule()
the long press of the side button
void loop_ButtonModule()
const int LED1
boolean _buttonPressed
const int _buttonPin
void buttonA_ShortPress_ButtonModule()
void refreshDelayButtonTouched_ButtonModule()
called by the feed operation to say the device is still running.. and count it as a button click.
void buttonA_LongPress_ButtonModule()
long press on buttonA (top button)
void setup_ButtonModule()
int LED1Status
int _buttonState
#define SINGLE_CLICK_BM
Definition: ButtonModule.h:24
void loop_ButtonProcessing()
the loop for buttonProcessing (extension of ButtonModule)
void buttonB_ShortPress()
the short press of the side button
void refreshDelayButtonTouched_ButtonProcessing()
called by the feed operation to say the device is still running.. and count it as a button click.
void setup_ButtonProcessing()
void buttonA_LongPress()
defines M5 info: https://docs.rs-online.com/e4eb/A700000008182827.pdf
void buttonB_LongPress()
the long press of the side button
void buttonA_ShortPress()
short press on buttonA (top button)
void callCallbackMain(int callbacksModuleId, int callbackType, char *message)
performs the indirect callback based on the callbackType
Definition: MainModule.cpp:333
#define CALLBACKS_BUTTON_MODULE
Definition: MainModule.cpp:222