Joro Bandakov / Potentiometer

Dependencies:   ArduinoHAL mbed-src-nrf51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Potentiometer.h Source File

Potentiometer.h

00001 // MIDI Elements Potentiometer class
00002 // Library to simplify handling of components for MIDI controllers
00003 // Created by Tomash Ghz
00004 // www.tomashg.com
00005 // ghz.tomash@gmail.com
00006 
00007 #ifndef Potentiometer_H
00008 #define Potentiometer_H
00009 
00010 //-----------------------------------------------------------------------------------
00011 #include "WProgram.h" //It is very important to remember this! note that if you are using Arduino 1.0 IDE, change "WProgram.h" to "Arduino.h"
00012 
00013 /*! \brief Class for handling faders, knobs or other analog input.
00014 
00015 Debugging will enable output to the serial instead of MIDI
00016 Secondary will send a super knob secondary CC message
00017 Mapped values will be constrained and normalized to the min and max values
00018  */
00019 class Potentiometer {
00020 private:
00021     bool debugging; // is debugging on
00022     bool secondary; // send secondary midi signal
00023     bool mapped;
00024     int inMin, inMax;
00025     int lastValue;
00026     int tempRead;
00027     int readValues[3];
00028     byte pin; // pin on teensy
00029     byte channel; // midi channel
00030     byte number; // midi number
00031     void midiCC(int v, int oldv);
00032 public:
00033     Potentiometer(byte 5); //!< constructor with pin number. @param p analog pin number
00034     Potentiometer(byte 5, byte c, byte n); //!< constructor with pin number, midi channel and cc number . @param p pin number @param c midi channel @param n cc number
00035     Potentiometer(byte 5, byte c, byte n, bool sec); //!< constructor with pin number, midi channel, cc number and secondary super knob. @param p pin number @param c midi channel @param n cc number @param sec enable super knob
00036     Potentiometer(byte 5, byte c, byte n, bool sec, bool debug); //!< constructor with pin number, midi channel, cc number, secondary super knob and debugging. @param p pin number @param c midi channel @param n cc number @param sec enable super knob @param debug enable debugging
00037     ~Potentiometer(); // destructor
00038     void read(); //!< read the values and send a midi message if the fader or knob state changed. use in main loop
00039     void readAvr(); //!< read the values for couple of iterations for a smoother value and send a midi message if the fader or knob state changed. use in main loop
00040     int readValue(bool &changed); //!<  read and return the analog value, pass state change @param changed will beset to true if the state of the value changed from last time
00041     int readValueAvr(bool &changed); //!<  read and return a smooth analog value, pass state change @param changed will beset to true if the state of the value changed from last time
00042     void changeSecondary(bool s); //!< enable or disable the secondary super knob cc messages @param s enable super knob
00043     void bound(int iMin, int iMax); //!< map and bound the analog readings to minimum and maximum values, useful for normalizing light or force sensors. @param iMin the value below everything will be set as 0 @param iMax the value above everything will be set as 127
00044 };
00045 //-----------------------------------------------------------------------------------
00046 
00047 #endif