Closed rogervila closed 8 years ago
Sorry for the delay, I'm going to have a look.
Ok, there are several issues there:
#define
)Here's an edited version, let me know if it works for you:
/*
* Roger Vilà - Midi Controler Project
* Francois Best - Edited 19/09/2014
*/
#include <MIDI.h>
//Starting MIDI
MIDI_CREATE_DEFAULT_INSTANCE();
//VARIABLES --------------------------------------------------------------------
// The Led will shine while the button is pressed
static const int led = 13;
// Button1 sends note, button2 sends Control Change
static const int button1 = 2;
static const int button2 = 4;
// Last button state counter
int lastB1State = 0;
int lastB2State = 0;
// Curent button state counter
int currentB1State = 0;
int currentB2State = 0;
// Note 60 = C
static const int note = 60;
// Control 16 = general purpose
static const int cc = 16;
// -----------------------------------------------------------------------------
inline void readB1()
{
//BUTTON1 = B1 = piano key
currentB1State = digitalRead(button1);
if (currentB1State != lastB1State)
{
// Take advantage of 0 velocity = note off.
MIDI.sendNoteOn(note, currentB1State == LOW ? 0 : 127, 1);
digitalWrite(led, currentB1State);
lastB1State = currentB1State;
}
}
inline void readB2()
{
currentB2State = digitalRead(button2);
if (currentB2State != lastB2State)
{
MIDI.sendControlChange(cc, currentB1State == LOW ? 0 : 127, 1);
digitalWrite(led, currentB1State);
lastB2State = currentB2State;
}
}
// -----------------------------------------------------------------------------
void setup()
{
MIDI.begin();
Serial.begin(115200);
pinMode(led, OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
// Initialize last button states with current pin values
// (in case program starts with one button already pressed)
lastB1State = digitalRead(button1);
lastB2State = digitalRead(button2);
}
void loop()
{
readB1();
readB2();
delay(50);
}
may i in addition suggest to use digitalIOPerformance - regards
Hello,
I'm creating my own MIDI Controller using the Arduino MIDI library. I succeed sending notes into Ableton Live, but I have some problems sending MIDI controls. I want to trigger a loop with a button but Ableton Live overflows and I have to close it. Maybe should I use another CC number? or another Arduino input? I selected cc 16 because it's for general purpose (i read it here: http://nickfever.com/402/production-tips-and-resources/midi-cc-list/)
Here is my code:
Thank you very much.