Potentiometers
Advanced potentiometer
This sketch demonstrates the advanced implementation of a potentiometer.
With this approach you can extend the base class (CtrlPot) into your own class, and expand on the base functionality as you please. The sky is the limit here. The inheriting class overrides the onValueChange method. Within this method you can add your desired actions.
The code
#include <CtrlPot.h>
// Extend the CtrlPot class into a CustomPot class.
class CustomPot : public CtrlPot
{
public:
CustomPot(uint8_t sig, int maxOutputValue, float sensitivity) : CtrlPot(sig, maxOutputValue, sensitivity) { }
protected:
void onValueChange(int value) override
{
Serial.print("Advanced pot value: ");
Serial.println(value);
}
};
// Create a potentiometer with the pin number, max. output value & sensitivity margin (can be 0.01 to 100).
CustomPot potentiometer(A0, 100, 0.05);
void setup() {
Serial.begin(9600);
}
void loop() {
// The process method will keep polling our potentiometer object and handle all it's functionality.
potentiometer.process();
}