po

Dependencies:   ArduinoHAL mbed-src-nrf51822

Committer:
siridjen
Date:
Tue Nov 24 22:31:58 2015 +0000
Revision:
3:7860aea79272
Parent:
0:03c039c2a00d
pot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
siridjen 0:03c039c2a00d 1 // MIDI Elements Potentiometer class
siridjen 0:03c039c2a00d 2 // Library to simplify handling of components for MIDI controllers
siridjen 0:03c039c2a00d 3 // Created by Tomash Ghz
siridjen 0:03c039c2a00d 4 // www.tomashg.com
siridjen 0:03c039c2a00d 5 // ghz.tomash@gmail.com
siridjen 0:03c039c2a00d 6
siridjen 0:03c039c2a00d 7 #ifndef Potentiometer_H
siridjen 0:03c039c2a00d 8 #define Potentiometer_H
siridjen 0:03c039c2a00d 9
siridjen 0:03c039c2a00d 10 //-----------------------------------------------------------------------------------
siridjen 0:03c039c2a00d 11 #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"
siridjen 0:03c039c2a00d 12
siridjen 0:03c039c2a00d 13 /*! \brief Class for handling faders, knobs or other analog input.
siridjen 0:03c039c2a00d 14
siridjen 0:03c039c2a00d 15 Debugging will enable output to the serial instead of MIDI
siridjen 0:03c039c2a00d 16 Secondary will send a super knob secondary CC message
siridjen 0:03c039c2a00d 17 Mapped values will be constrained and normalized to the min and max values
siridjen 0:03c039c2a00d 18 */
siridjen 0:03c039c2a00d 19 class Potentiometer {
siridjen 0:03c039c2a00d 20 private:
siridjen 0:03c039c2a00d 21 bool debugging; // is debugging on
siridjen 0:03c039c2a00d 22 bool secondary; // send secondary midi signal
siridjen 0:03c039c2a00d 23 bool mapped;
siridjen 0:03c039c2a00d 24 int inMin, inMax;
siridjen 0:03c039c2a00d 25 int lastValue;
siridjen 0:03c039c2a00d 26 int tempRead;
siridjen 0:03c039c2a00d 27 int readValues[3];
siridjen 0:03c039c2a00d 28 byte pin; // pin on teensy
siridjen 0:03c039c2a00d 29 byte channel; // midi channel
siridjen 0:03c039c2a00d 30 byte number; // midi number
siridjen 0:03c039c2a00d 31 void midiCC(int v, int oldv);
siridjen 0:03c039c2a00d 32 public:
siridjen 0:03c039c2a00d 33 Potentiometer(byte 5); //!< constructor with pin number. @param p analog pin number
siridjen 0:03c039c2a00d 34 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
siridjen 0:03c039c2a00d 35 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
siridjen 0:03c039c2a00d 36 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
siridjen 0:03c039c2a00d 37 ~Potentiometer(); // destructor
siridjen 0:03c039c2a00d 38 void read(); //!< read the values and send a midi message if the fader or knob state changed. use in main loop
siridjen 0:03c039c2a00d 39 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
siridjen 0:03c039c2a00d 40 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
siridjen 0:03c039c2a00d 41 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
siridjen 0:03c039c2a00d 42 void changeSecondary(bool s); //!< enable or disable the secondary super knob cc messages @param s enable super knob
siridjen 0:03c039c2a00d 43 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
siridjen 0:03c039c2a00d 44 };
siridjen 0:03c039c2a00d 45 //-----------------------------------------------------------------------------------
siridjen 0:03c039c2a00d 46
siridjen 0:03c039c2a00d 47 #endif