Automatically turn devices on or off when values cross a set threshold.
UltiBlox on GitHub | UltiBlox Home
The ActiveThreshold library helps you monitor values and trigger actions based on configurable thresholds, making it ideal for automating responses to sensor data or other input signals. With customizable activation modes and callback support, ActiveThreshold offers a straightforward way to implement threshold-based control in embedded systems. If no custom threshold is set, the default threshold is used, which can be particularly useful for initial testing or fallback scenarios.
- Set custom thresholds for activation.
- Configure Active-High or Active-Low behavior.
- Store thresholds persistently using EEPROM, with a default fallback.
- Register callbacks for activation and deactivation events.
- Increment or decrement thresholds with automatic EEPROM updates.
- Open the Arduino IDE.
- Go to Tools > Manage Libraries.
- Search for UltiBlox ActiveThreshold and click Install.
- Access example sketches under File > Examples > UltiBlox ActiveThreshold.
-
Clone the Repository:
git clone git@github.com:UltiBlox/ActiveThreshold.git ~/workspace/ActiveThreshold cd ~/workspace/ActiveThreshold
-
Prepare the Environment: Run the
prepare.shscript to set up dependencies:bash prepare.sh
-
Install the Library:
-
Copy Installation:
bash install.sh
-
Symlink Installation (for active development):
bash install-symlink.sh
-
-
Build Examples: Compile example sketches with:
bash build.sh
- EEPROM Library: Required for persistent storage of thresholds.
- Arduino Core Library
Refer to the ActiveThresholdExample.ino file for a complete usage example demonstrating threshold-based activation and deactivation.
init()Initializes the threshold system.
setDefaultThreshold(int defaultThreshold)Sets a default threshold value for triggering activation if no custom threshold is set or stored in EEPROM. This fallback threshold ensures the system can operate without requiring a stored value.
setThreshold(int threshold)Defines a custom threshold value.
setActiveHigh(bool isActiveHigh)Sets activation mode to active-high (true), activating when the value meets or exceeds the threshold, or active-low (false), activating when the value falls below the threshold.
onActive(void (*callback)())Registers a callback function to execute when the threshold becomes active.
onInactive(void (*callback)())Registers a callback function to execute when the threshold becomes inactive.
evaluate(int value)Evaluates the input value against the threshold, monitoring for changes in the activation state and triggering the appropriate callback if a state change occurs.
loadThresholdFromEEPROM()Loads the saved threshold from EEPROM, if available. If no threshold is stored, the default threshold will be used.
saveThresholdToEEPROM()Saves the current threshold to EEPROM for persistence across power cycles.
incrementThreshold()Increases the threshold value by one and updates the stored value in EEPROM.
decrementThreshold()Decreases the threshold value by one and updates the stored value in EEPROM.
getThreshold() constReturns the current active threshold value, whether it’s the default or a custom-set threshold.
- ActiveThresholdExample.ino: Demonstrates how to set up and use the library to activate or deactivate a pin based on sensor input.