From f9350d9cde40c88cd87aa93cf0274014314eddf2 Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Thu, 2 Jan 2025 21:02:47 +0200 Subject: [PATCH 1/6] Update BfButtonManager.cpp to add support for 0V ADC button Some shields e.g. the DFR0009 by DFRobot https://wiki.dfrobot.com/LCD_KeyPad_Shield_For_Arduino_SKU__DFR0009 Include buttons that pull down to 0V when pressed. This change adds support for these buttons. --- src/BfButtonManager.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/BfButtonManager.cpp b/src/BfButtonManager.cpp index c49ed64..f178e57 100644 --- a/src/BfButtonManager.cpp +++ b/src/BfButtonManager.cpp @@ -47,6 +47,12 @@ BfButtonManager& BfButtonManager::setADCResolution(uint16_t resolution) { this->_adcResolution = resolution; return *this; } + +BfButtonManager& BfButtonManager::setADCBounds(uint16_t lowerBound, uint16_t upperBound) { + this->_adcLowerBound = lowerBound; + this->_adcResolution = upperBound; + return *this; +} BfButtonManager& BfButtonManager::addButton(BfButton* btn, uint16_t minVoltageReading, uint16_t maxVoltageReading) { uint8_t _b = btn->getID(); @@ -102,9 +108,9 @@ int8_t BfButtonManager::_readButton() { } z = _sum / 4; - if (z >= 100 || z < this->_adcResolution) { + if (z >= this->_adcLowerBound || z < this->_adcResolution) { for (int8_t _b = 0; _b < this->_buttonCount; _b++) { - if (z > this->_btnVoltageLowerBounds[_b] && z < this->_btnVoltageUpperBounds[_b]) { + if (z >= this->_btnVoltageLowerBounds[_b] && z <= this->_btnVoltageUpperBounds[_b]) { _button = _b; break; } From 9c96bf8e7987be87b9a56653333842eeafa7943e Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Thu, 2 Jan 2025 21:19:43 +0200 Subject: [PATCH 2/6] Update BfButtonManager.h to add support for 0V ADC button Some shields e.g. the DFR0009 by DFRobot https://wiki.dfrobot.com/LCD_KeyPad_Shield_For_Arduino_SKU__DFR0009 Include buttons that pull down to 0V when pressed. This change adds support for these buttons. --- src/BfButtonManager.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BfButtonManager.h b/src/BfButtonManager.h index 4d9cfd7..3a09d44 100644 --- a/src/BfButtonManager.h +++ b/src/BfButtonManager.h @@ -46,6 +46,12 @@ class BfButtonManager { * The library will set build-in ADC for Arduino and ESP32 by default. */ BfButtonManager& setADCResolution(uint16_t resolution); + + /* + * Set the lower & upper bounds for the acceptable voltage range for ADC buttons (upperBound = resolution) + * defaults: lowerBound = 50, upperBound = 1024 (4096 for ESP32) + */ + BfButtonManager& setADCBounds(uint16_t lowerBound, uint16_t upperBound); /* * Add button to button array. @@ -88,6 +94,8 @@ class BfButtonManager { #else uint16_t _adcResolution = 1024; #endif + + uint16_t _adcLowerBound = 100; unsigned long _lastLoop = 0; uint8_t _loopInterval = 20; @@ -105,4 +113,4 @@ class BfButtonManager { int8_t _readButton(); }; -#endif // BfButtonManager_h \ No newline at end of file +#endif // BfButtonManager_h From 3252e3454167fa41c0f6a563b8003f99f96d2d5d Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Thu, 2 Jan 2025 21:26:03 +0200 Subject: [PATCH 3/6] Update BfButtonManager.cpp add support for 0V ADC button Some shields e.g. the DFR0009 by DFRobot https://wiki.dfrobot.com/LCD_KeyPad_Shield_For_Arduino_SKU__DFR0009 include buttons that pull down to 0V when pressed. This change adds support for these buttons. --- src/BfButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BfButtonManager.cpp b/src/BfButtonManager.cpp index f178e57..48f6394 100644 --- a/src/BfButtonManager.cpp +++ b/src/BfButtonManager.cpp @@ -108,7 +108,7 @@ int8_t BfButtonManager::_readButton() { } z = _sum / 4; - if (z >= this->_adcLowerBound || z < this->_adcResolution) { + if (z >= this->_adcLowerBound || z <= this->_adcResolution) { for (int8_t _b = 0; _b < this->_buttonCount; _b++) { if (z >= this->_btnVoltageLowerBounds[_b] && z <= this->_btnVoltageUpperBounds[_b]) { _button = _b; From dc4041b39fb37ae68224e1acc4691e69b4250e08 Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Thu, 2 Jan 2025 21:33:00 +0200 Subject: [PATCH 4/6] Update BfButtonManager.h update comment --- src/BfButtonManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BfButtonManager.h b/src/BfButtonManager.h index 3a09d44..78ba6ce 100644 --- a/src/BfButtonManager.h +++ b/src/BfButtonManager.h @@ -48,7 +48,7 @@ class BfButtonManager { BfButtonManager& setADCResolution(uint16_t resolution); /* - * Set the lower & upper bounds for the acceptable voltage range for ADC buttons (upperBound = resolution) + * Set the lower & upper bounds to define the acceptable range for ADC buttons (upperBound = resolution) * defaults: lowerBound = 50, upperBound = 1024 (4096 for ESP32) */ BfButtonManager& setADCBounds(uint16_t lowerBound, uint16_t upperBound); From b4f4c1e0c860d37dad2d3a6a82678db6b4e31e9b Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Thu, 2 Jan 2025 21:52:16 +0200 Subject: [PATCH 5/6] Update BfButtonManager.cpp modify printReading to use lowerBound --- src/BfButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BfButtonManager.cpp b/src/BfButtonManager.cpp index 48f6394..27135ca 100644 --- a/src/BfButtonManager.cpp +++ b/src/BfButtonManager.cpp @@ -82,7 +82,7 @@ void BfButtonManager::loop() { uint16_t BfButtonManager::printReading(uint8_t pin) { int z; z = analogRead(pin); - if (z > 100) Serial.println(z); + if (z >= this->_adcLowerBound) Serial.println(z); return z; } From 9d005f8f586510e85d58897df028048f6ec0d7ae Mon Sep 17 00:00:00 2001 From: mountain-lion-za Date: Mon, 6 Jan 2025 22:13:24 +0200 Subject: [PATCH 6/6] Update README.md Add note indicating what is modified in this fork --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc35cbf..a8bfbfd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ Powerful button tools for managing various button events of standalone button or `BfButton` class handled standalone button debouncing, trigger callback function for single press, double press, and long press events. The class can distinguish different pressing pattern and trigger corresponding callback, i.e. single press vs double press. -`BfButtonManager` class manage multiple buttons with single analog pin. The class also provide `printReading()` method for you to check the analog pin reading. In theory you may add more buttons in the circuit. +`BfButtonManager` class manage multiple buttons with single analog pin. The class also provide `printReading()` method for you to check the analog pin reading. In theory you may add more buttons in the circuit. + +**This fork exists only to modify the BfButtonManager class, adding support for ADC buttons that pull down to 0.** +A pull request has been submitted to merge this back to the parent project, but no response from the original author (mickey9801) yet. ## Installation