Skip to content

Commit 71573f8

Browse files
committed
Update
Update readme and ESP32 input pulldown example.
1 parent a8a419e commit 71573f8

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Arduino button debounce library for various switch types, port expanders and oth
1212

1313
## Examples (Wokwi)
1414

15-
- Do a trial run for evaluation.
15+
- Do a test run for evaluation.
1616
- Your suggestions, Issues and Discussions are welcome [here](https://github.com/Dlloydev/Toggle).
1717

1818
| ESP32-S2 | UNO |
@@ -24,6 +24,7 @@ Arduino button debounce library for various switch types, port expanders and oth
2424
| [Released_For.ino](https://wokwi.com/projects/334458628485415508) | [Released_For.ino](https://wokwi.com/projects/334458460245590611) |
2525
| [Retrigger_While_Pressed.ino](https://wokwi.com/projects/334459280465855059) | [Retrigger_While_Pressed.ino](https://wokwi.com/projects/334458963671122515) |
2626
| [Press_Code.ino](https://wokwi.com/projects/334320246564323924) | [Press_Code.ino](https://wokwi.com/projects/334284248581145170) |
27+
| [ESP32_Input_Pulldown.ino](https://wokwi.com/projects/334554744838160980) | |
2728

2829
## Toggle Library Reference
2930

@@ -310,7 +311,7 @@ if (retrigger(500)) {
310311
- Detection of long (greater than 1 sec) presses and short (less than 1 sec) presses occurs if the first press is 0.4 sec or longer.
311312
- Detect up to 15 short presses
312313
- Detect up to 14 long presses
313-
- Returns code after button is released for 1.4 sec
314+
- Returns code after button is released for 1 sec
314315
- simplifies your code while adding maximum functionality to one button
315316

316317
##### Example
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*********************************************************************
2+
ESP32-S2 INPUT_PULLDOWN EXAMPLE:
3+
This example blinks the built in LED as configured below.
4+
Try on Wokwi ESP32-S2: https://wokwi.com/projects/334554744838160980
5+
********************************************************************/
6+
7+
#include <Toggle.h>
8+
9+
const byte buttonPin = 4;
10+
const byte ledPin = 16;
11+
12+
const unsigned int blinkMs = 100; // blink duration (ms)
13+
const byte blinkMode = 1; // 0: on change, 1: on press (default), 2: on release
14+
15+
Toggle button(buttonPin);
16+
17+
void setup() {
18+
button.begin(buttonPin);
19+
button.setInputInvert(1);
20+
pinMode(buttonPin, INPUT_PULLDOWN);
21+
pinMode(ledPin, OUTPUT);
22+
}
23+
24+
void loop() {
25+
button.poll();
26+
digitalWrite(ledPin, button.blink(blinkMs, blinkMode));
27+
delay(1);
28+
}

examples/Input_Pulldown/Input_Pulldown.ino

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Toggle.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,7 @@ void Toggle::begin(uint8_t inA, uint8_t inB) {
1717
_inB = inB;
1818
us_timestamp = micros();
1919
startUs = us_timestamp;
20-
if (_inA != 255) {
21-
if (_inputMode == inputMode::input_pullup) pinMode(_inA, INPUT_PULLUP);
22-
else if (_inputMode == inputMode::input) pinMode(_inA, INPUT);
23-
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
24-
else if (_inputMode == inputMode::input_pulldown) pinMode(_inA, INPUT_PULLDOWN);
25-
#endif
26-
}
27-
if (_inB != 255) {
28-
if (_inputMode == inputMode::input_pullup) pinMode(_inB, INPUT_PULLUP);
29-
else if (_inputMode == inputMode::input) pinMode(_inB, INPUT);
30-
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
31-
else if (_inputMode == inputMode::input_pulldown) pinMode(_inB, INPUT_PULLDOWN);
32-
#endif
33-
}
20+
setInputMode(inputMode::input_pullup);
3421
}
3522
}
3623

@@ -51,6 +38,20 @@ void Toggle::poll(uint8_t bit) {
5138

5239
void Toggle::setInputMode(inputMode inputMode) {
5340
_inputMode = inputMode;
41+
if (_inA != 255) {
42+
if (_inputMode == inputMode::input_pullup) pinMode(_inA, INPUT_PULLUP);
43+
else if (_inputMode == inputMode::input) pinMode(_inA, INPUT);
44+
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
45+
else if (_inputMode == inputMode::input_pulldown) pinMode(_inA, INPUT_PULLDOWN);
46+
#endif
47+
}
48+
if (_inB != 255) {
49+
if (_inputMode == inputMode::input_pullup) pinMode(_inB, INPUT_PULLUP);
50+
else if (_inputMode == inputMode::input) pinMode(_inB, INPUT);
51+
#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32))
52+
else if (_inputMode == inputMode::input_pulldown) pinMode(_inB, INPUT_PULLDOWN);
53+
#endif
54+
}
5455
}
5556

5657
void Toggle::setSamplePeriodUs(uint16_t period) {

0 commit comments

Comments
 (0)