[title]Event Driven GHI Potentiometer[/title]
My goal was to use the GHI Potentiometer Gadgeteer Module to adjust the volume of the Music Module, but readings were jumping all over the place.
I ended up writing a custom “Event Driven” driver for the module. It will poll the potentiometer value every 5 miliseconds and calculates the average value over 10 polled values. If the average value differs more than 1 from the last reported value, the event will be raised.
To use the custom driver:
- Do NOT add the potentiometer module to the Gadgeteer designer
- Add a new class to your project
- Replace the contents of the new class with the source code below
- Add the following line after your class definition
- Initialize the module with
potentiometer = new GTM.MischaBoender.GHIPotentiometer([SocketNumber]);
- Wire-up the event handler with
potentiometer.PotentiometerChanged += new GTM.MischaBoender.GHIPotentiometer.PotentiometerEventHandler(potentiometer_PotentiometerChanged);
In the usage example I use the LED7R module for some visual feedback.