Skip to content

Commit cc415d4

Browse files
committed
Update README. Prepare for release
1 parent 81c34e6 commit cc415d4

8 files changed

Lines changed: 108 additions & 30 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.development

README.md

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
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

3535
void 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&#8486; = 5000&#8486;
213271
3.3V/4095 = 0.81mV
214272

215273
Button|MultiMeter Measurement|Expected Value
216-
------|----------------------|-----------------
274+
:----:|----------------------|-----------------
217275
1 |2.62V |3259
218276
2 |1.96V~1.97V |2420~2432
219277
3 |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

226284
Button|Circuit Measurement|Serial Debug Data|Calculated Voltage w' Adjustment
227-
------|-------------------|-----------------|------------------
285+
:----:|-------------------|-----------------|------------------
228286
1 |2.61V |3070~3103 |2.59V~2.61V
229287
2 |1.95V~1.96V |2237~2255 |1.92V~1.93V
230288
3 |1.30V |1456~1461 |~1.29V

examples/basic_usage/basic_usage.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <MultiButtons.h>
22

3-
const int btnPin = 14;
3+
const int btnPin = 35;
44

55
// Declare voltage ranges for each button
66
int voltageRanges[][2] = {
@@ -24,6 +24,10 @@ MultiButtons mb(btnPin, btnCount, voltageRanges, buttonHandler, 4095, BTN_TRIGGE
2424

2525
void setup() {
2626
Serial.begin(115200);
27+
while (!Serial) {
28+
;
29+
}
30+
Serial.println();
2731

2832
mb.begin(); // Prepare reading button state
2933

@@ -32,4 +36,4 @@ void setup() {
3236

3337
void loop() {
3438
mb.loop(); // Read button state with debouncing
35-
}
39+
}

examples/pin_reading/pin_reading.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ int reading, sum, avg;
55

66
void setup() {
77
Serial.begin(115200);
8+
while (!Serial) {
9+
;
10+
}
11+
Serial.println();
812
}
913

1014
void loop() {

keywords.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
# Datatypes (KEYWORD1)
77
#######################################
88

9-
MultiButtons KEYWORD1
9+
MultiButtons KEYWORD1
1010

1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

15-
begin KEYWORD2
16-
loop KEYWORD2
17-
printReading KEYWORD2
18-
isPressingAny KEYWORD2
19-
isPressing KEYWORD2
20-
getTriggerEdge KEYWORD2
21-
setTriggerEdge KEYWORD2
22-
_getButton KEYWORD2
23-
_readButton KEYWORD2
15+
begin KEYWORD2
16+
loop KEYWORD2
17+
printReading KEYWORD2
18+
isPressingAny KEYWORD2
19+
isPressing KEYWORD2
20+
getTriggerEdge KEYWORD2
21+
setTriggerEdge KEYWORD2
22+
_getButton KEYWORD2
23+
_readButton KEYWORD2
2424

2525
#######################################
2626
# Instances (KEYWORD2)
@@ -30,7 +30,7 @@ _readButton KEYWORD2
3030
#######################################
3131
# Constants (LITERAL1)
3232
#######################################
33-
BTN_READ_PHASE_1ST_PASS LITERAL1
34-
BTN_READ_PHASE_2ND_PASS LITERAL1
35-
BTN_TRIGGER_EDGE_PRESS LITERAL1
36-
BTN_TRIGGER_EDGE_RELEASE LITERAL1
33+
BTN_READ_PHASE_1ST_PASS LITERAL1
34+
BTN_READ_PHASE_2ND_PASS LITERAL1
35+
BTN_TRIGGER_EDGE_PRESS LITERAL1
36+
BTN_TRIGGER_EDGE_RELEASE LITERAL1

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=MultiButtons
2+
version=1.0.0
3+
author=Mickey Chan <developer@comicparty.com>
4+
maintainer=Mickey Chan <developer@comicparty.com>
5+
sentence=Library for handling multiple buttons with single analog pin for ESP32.
6+
paragraph=It will trigger callback function upon button pressed. The library handled button debouncing, and you may decide the trigger edge for button event - on press (default) or on release.
7+
category=Signal Input
8+
url=https://github.com/mickey9801/MultiButtons
9+
architectures=*
10+
includes=MultiButtons.h
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int MultiButtons::_readButton () {
110110
int MultiButtons::printReading(int pin) {
111111
int z;
112112
z = analogRead(pin);
113-
if (z > 0) Serial.println(z);
113+
if (z > 100) Serial.println(z);
114114
return z;
115115
}
116116

File renamed without changes.

0 commit comments

Comments
 (0)