po

Dependencies:   ArduinoHAL mbed-src-nrf51822

Committer:
siridjen
Date:
Tue Nov 24 22:18:32 2015 +0000
Revision:
0:03c039c2a00d
Child:
1:a8ea5eba6376
potonciometer1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
siridjen 0:03c039c2a00d 1 // MIDI Elements Button 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 Button_H
siridjen 0:03c039c2a00d 8 #define Button_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 #include <MIDIBounce.h>
siridjen 0:03c039c2a00d 13
siridjen 0:03c039c2a00d 14 /*! \brief Class for handling push button switches.
siridjen 0:03c039c2a00d 15
siridjen 0:03c039c2a00d 16 Connect the button to ground and input pin, there is no need for a pull-up resistor, it is enabled internally.
siridjen 0:03c039c2a00d 17 Enable Secondary to send secondary CC messages. (used for mapping momentary switches in Ableton)
siridjen 0:03c039c2a00d 18 Enable debug to print to serial port instead of midi.
siridjen 0:03c039c2a00d 19 */
siridjen 0:03c039c2a00d 20
siridjen 0:03c039c2a00d 21 class Button {
siridjen 0:03c039c2a00d 22 private:
siridjen 0:03c039c2a00d 23 MIDIBounce *bButn; // bounce class button
siridjen 0:03c039c2a00d 24 bool debugging; // is debugging on
siridjen 0:03c039c2a00d 25 bool secondary; // send secondary midi signal
siridjen 0:03c039c2a00d 26 byte pin; // pin on teensy
siridjen 0:03c039c2a00d 27 byte channel; // midi channel
siridjen 0:03c039c2a00d 28 byte number; // midi number
siridjen 0:03c039c2a00d 29 byte velocity; // midi velocity
siridjen 0:03c039c2a00d 30 void noteOnOff(bool v); // send note on off
siridjen 0:03c039c2a00d 31 public:
siridjen 0:03c039c2a00d 32 Button(byte p); //!< constructor with pin number. @param p pin number
siridjen 0:03c039c2a00d 33 Button(byte p, byte c, byte n); //!< constructor with pin number, midi channel and midi note. @param p pin number @param c midi channel @param n midi note
siridjen 0:03c039c2a00d 34 Button(byte p, byte c, byte n, bool sec); //!< constructor with pin number, midi channel, midi note and secondary messages. @param p pin number @param c midi channel @param n midi note @param sec enable secondary messages
siridjen 0:03c039c2a00d 35 Button(byte p, byte c, byte n, bool sec, bool debug); //!< constructor with pin number, midi channel, midi note, secondary messages and debugging. @param p pin number @param c midi channel @param n midi note @param sec enable secondary message @param debug enable debugging
siridjen 0:03c039c2a00d 36 ~Button(); // destructor
siridjen 0:03c039c2a00d 37 void read(); //!< read the values and send a midi message if the button state changed. use in main loop
siridjen 0:03c039c2a00d 38 bool readValue(bool &changed); //!< read the values and return if the button is pressed, pass state change @param changed will beset to true if the state of the button changed
siridjen 0:03c039c2a00d 39 void setVelocity(byte v); //!< change the note on velocity value of the outgoing midi message. @param v set velocity value
siridjen 0:03c039c2a00d 40 };
siridjen 0:03c039c2a00d 41 //-----------------------------------------------------------------------------------
siridjen 0:03c039c2a00d 42
siridjen 0:03c039c2a00d 43 #endif