Hi i wondered if there was a way of pausing after a button is pressed. When im running my 4 button controller though guitar rig and ableton the buttons double click sometimes.
// include MIDI library
#include <MIDI.h>
// read digital pins number 2, 4, 7, 8
int pushButton2 = 2;
int pushButton4 = 4;
int pushButton7 = 7;
int pushButton8 = 8;
// checks if the button is pressed
int buttonState2 = 0;
int buttonState4 = 0;
int buttonState7 = 0;
int buttonState8 = 0;
// play/stop notes in relation to buttons pressed
int note2 = 0;
int note4 = 0;
int note7 = 0;
int note8 = 0;
// read potentiometer value
int analogValue = 0;
// maximum MIDI value is 127, first/previous potentiometer
// move has to always be different than previous value
int lastAnalogValue = 128;
void setup() {
delay (1000);
// slows connection so you dont have to reset board
MIDI.begin(4);
// 115200 hairless MIDI
Serial.begin(115200);
pinMode(pushButton2, INPUT);
pinMode(pushButton4, INPUT);
pinMode(pushButton7, INPUT);
pinMode(pushButton8, INPUT);
}
void loop() {
// read state of buttons
int buttonState2 = digitalRead(pushButton2);
int buttonState4 = digitalRead(pushButton4);
int buttonState7 = digitalRead(pushButton7);
int buttonState8 = digitalRead(pushButton8);
// Button 2
// when button pressed:
if (buttonState2 == HIGH) {
// if note not playing
if (note2 == 0) {
// play note (note number, velocity, channel)
// more info: Arduino MIDI Library: MIDI_Class Class Reference
// MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
// 55 = G3, 127 = trigger note with max volume
MIDI.sendControlChange(80,127,1);
// note is playing
note2 = 1;
}
// when button released
} else {
// if note playing
if (note2 == 1) {
// if playing - stop
MIDI.sendControlChange(80,0,1);
}
// if button released note is off
note2 = 0;
}
// Button 4
// when button pressed:
if (buttonState4 == HIGH) {
// if note not playing
if (note4 == 0) {
// play note (note number, velocity, channel)
// more info: Arduino MIDI Library: MIDI_Class Class Reference
// MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
// 55 = G3, 127 = trigger note with max volume
MIDI.sendControlChange(81,127,1);
// note is playing
note4 = 1;
}
// when button released
} else {
// if note playing
if (note4 == 1) {
// if playing - stop
MIDI.sendControlChange(81,0,1);
}
// if button released note is off
note4 = 0;
}
// Button 7
// when button pressed:
if (buttonState7 == HIGH) {
// if note not playing
if (note7 == 0) {
// play note (note number, velocity, channel)
// more info: Arduino MIDI Library: MIDI_Class Class Reference
// MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
// 55 = G3, 127 = trigger note with max volume
MIDI.sendControlChange(82,127,1);
// note is playing
note7 = 1;
}
// when button released
} else {
// if note playing
if (note7 == 1) {
// if playing - stop
MIDI.sendControlChange(82,0,1);
}
// if button released note is off
note7 = 0;
}
// Button 8
// when button pressed:
if (buttonState8 == HIGH) {
// if note not playing
if (note8 == 0) {
// play note (note number, velocity, channel)
// more info: Arduino MIDI Library: MIDI_Class Class Reference
// MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
// 55 = G3, 127 = trigger note with max volume
MIDI.sendControlChange(83,127,1);
// note is playing
note8 = 1;
}
// when button released
} else {
// if note playing
if (note8 == 1) {
// if playing - stop
MIDI.sendControlChange(83,0,1);
}
// if button released note is off
note8 = 0;
}
delay(1);
}
