1- # Multiple Buttons Module
1+ # Multiple Buttons Library
22
3- This is a module for handling multiple buttons with single analog pin for ESP32. It will trigger callback function upon button pressed.
3+ This is a library for handling multiple buttons with single analog pin for ESP32. It will trigger callback function upon button pressed.
44
5- The module handled button debouncing, and you may decide the trigger edge for button event - on press (default) or on release.
5+ The library handled button debouncing, and you may decide the trigger edge for button event - on press (default) or on release.
66
7- It also provide ` printReading() ` method for you to check the analog pin reading.
7+ It also provide ` printReading() ` method for you to check the analog pin reading.
88
9- In theory you may add more buttons in the circuit.
9+ In theory you may add more buttons in the circuit.
1010
1111## Reference Circuit
1212
1313![ Multiple Button Circuit] ( https://4.bp.blogspot.com/_mhuuHR0dxnU/TF7Kesn5gmI/AAAAAAAAENg/JeRCtP2oNNs/s1600/analog_button_input.png )
1414
1515## Installation
1616
17- [ Download or clone this repository into your arduino libraries directory] ( https://help.github.com/articles/cloning-a-repository/ )
17+ [ Download or clone this repository into your arduino libraries directory] ( https://help.github.com/articles/cloning-a-repository/ )
1818
1919## Determin Voltage Readings for Each Button
2020
21- To provide voltage range for each button, you may check the actual readings with ` printReading() ` method.
21+ To provide voltage range for each button, you may check the actual readings with ` printReading() ` method.
2222
23- The following sketch can calculate the avarage reading of a button:
23+ The following sketch can calculate the avarage reading of a button from 5 readings :
2424
2525``` cpp
2626#include < MultiButtons.h>
@@ -34,7 +34,7 @@ void setup() {
3434
3535void loop () {
3636 static int i = 0;
37- reading = MultiButtons::printReading(35 );
37+ reading = MultiButtons::printReading(14 );
3838 if (reading > 0) {
3939 buffer[ i] = reading;
4040 if (i == 4) {
@@ -98,7 +98,7 @@ void loop() {
9898 }
9999 ```
100100
101- 4 . ** Construct MultiButtons object**
101+ 4 . ** Create MultiButtons object**
102102
103103 ``` cpp
104104 MultiButtons mb (btnPin, btnCount, voltageRanges, buttonHandler, 4095, BTN_TRIGGER_EDGE_PRESS);
@@ -116,7 +116,7 @@ void loop() {
116116 int triggerEdge | Which edge trigger button press event.<br>On press (0, default) or on release (1)
117117
118118
119- 5. **Prepare MultiButtons object for reading analog pin**
119+ 5. **Setup MultiButtons object for reading analog pin**
120120
121121 ```cpp
122122 void setup() {
@@ -187,6 +187,64 @@ void loop() {
187187}
188188```
189189
190+ ## Other methods
191+
192+ - *static* int **printReading (** int **pin )**
193+
194+ Print analog pin reading through Serial port and return the reading.
195+
196+ ```cpp
197+ int reading = MultiButtons::printReading(14);
198+ ```
199+
200+ - * static* bool ** isPressingAny (** int ** pin )**
201+
202+ Class method for checking if any button in the button array pressed.
203+
204+ ``` cpp
205+ bool result = MultiButtons::isPressingAny(14 );
206+ ```
207+
208+ - bool ** isPressing ()**
209+
210+ Object method version of ` isPressingAny() ` .
211+
212+ ``` cpp
213+ bool result = mb.isPressing();
214+ ```
215+
216+ - bool ** isPressing (** int ** btnIndex** ** )**
217+
218+ Check designated button is pressing. Button index begin from 0.
219+
220+ ``` cpp
221+ bool result = mb.isPressing(0 );
222+ ```
223+
224+ - int ** getTriggerEdge ()**
225+
226+ Retrieve trigger edge value.
227+
228+ ``` cpp
229+ int edge = mb.getTriggerEdge();
230+ ```
231+
232+ Possible value:
233+
234+ Edge |Value|Description
235+ :---------------------------|:---:|:----------
236+ BTN\_ TRIGGER\_ EDGE\_ PRESS | 0 | Trigger button event on press
237+ BTN\_ TRIGGER\_ EDGE\_ RELEASE | 1 | Trigger button event on release
238+
239+ - bool ** setTriggerEdge (** int ** edge )**
240+
241+ Set trigger edge. Return ` true ` when success, ` false ` if provide invalid value.
242+
243+ ``` cpp
244+ bool result = mb.setTriggerEdge(BTN_TRIGGER_EDGE_PRESS );
245+ ```
246+
247+
190248## Reference
191249
192250- [ Multiple button inputs using Arduino analog pin] ( https://rayshobby.net/wordpress/multiple-button-inputs-using-arduino-analog-pin/ )
@@ -213,7 +271,7 @@ R1+R2 = 5KΩ = 5000Ω
2132713.3V/4095 = 0.81mV
214272
215273Button|MultiMeter Measurement|Expected Value
216- ------ |----------------------|-----------------
274+ : ----: |----------------------|-----------------
2172751 |2.62V |3259
2182762 |1.96V~ 1.97V |2420~ 2432
2192773 |1.30V~ 1.31V |1605~ 1617
@@ -224,7 +282,7 @@ It is required an adjustment for ESP32 ADC with the following equation:
224282` Vout = e / 4095.0 * 3.3 + 0.1132 `
225283
226284Button|Circuit Measurement|Serial Debug Data|Calculated Voltage w' Adjustment
227- ------ |-------------------|-----------------|------------------
285+ : ----: |-------------------|-----------------|------------------
2282861 |2.61V |3070~ 3103 |2.59V~ 2.61V
2292872 |1.95V~ 1.96V |2237~ 2255 |1.92V~ 1.93V
2302883 |1.30V |1456~ 1461 |~ 1.29V
0 commit comments