1

I am building a simple arduino based midi controller to send cc midi messages. However I am able to send messages only through A0 (analog input).. Any help on this will be appreciated,..

 #include <MIDI.h>
int pot[] = {A0,A1,A2};
int AnaPinsNum = 3;
int potIn[] = {0,0,0};
int analogValue = 0;
int lastAnalogValue[] = {0,0,0};
 void setup() 
 {
 MIDI.begin(4);
 // 115200 hairless MIDI
 Serial.begin(115200);
 int i;
 for (i = 0; i < 3; i++);
 }
 void loop() {
 int i;
 for (i = 0; i < AnaPinsNum; i++)
 potIn[i] = analogRead(pot[i])/8;
 // potentiometer could be too sensitive and
 // give different (+-1) values.
 // send CC only when the difference between last value
 // is more than 1
 if ((potIn[i]-lastAnalogValue[i]) > 1 || (potIn[i]-lastAnalogValue[i]) < -1) {
 // value changed?
 if (potIn[i] != lastAnalogValue[i]) {
 // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
 // more info: http://arduinomidilib.sourceforge.net/a00001.html
 MIDI.sendControlChange(1, potIn[i], 1);
 lastAnalogValue[i] = potIn[i];
 }
 }
} 
asked Aug 26, 2015 at 15:29
3
  • Perhaps you want to send your values on different channels, or different controllers, instead of all on the same channel/controller combination...? Commented Aug 26, 2015 at 15:31
  • for (i = 0; i < 3; i++); - what is that line intended to do? Commented Aug 26, 2015 at 20:46
  • Yes I want to send different CC messages with different channel/value etc. in different inputs Commented Aug 27, 2015 at 5:36

1 Answer 1

0

Your logic is flawed here:

 int i;
 for (i = 0; i < AnaPinsNum; i++)
 potIn[i] = analogRead(pot[i]) / 8;
 // potentiometer could be too sensitive and
 // give different (+-1) values.
 // send CC only when the difference between last value
 // is more than 1
 if ((potIn[i] - lastAnalogValue[i]) > 1 || (potIn[i] - lastAnalogValue[i]) < -1) {
 // value changed?
 if (potIn[i] != lastAnalogValue[i]) {
 // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
 // more info: http://arduinomidilib.sourceforge.net/a00001.html
 MIDI.sendControlChange(1, potIn[i], 1);
 lastAnalogValue[i] = potIn[i];
 }
 }

The first three lines read all three analog pins:

 int i;
 for (i = 0; i < AnaPinsNum; i++)
 potIn[i] = analogRead(pot[i]) / 8;

However then, outside the loop, you are using the value of i which will now be 4, and outside the array bounds. You need to bracket the whole lot, eg.

 int i;
 for (i = 0; i < AnaPinsNum; i++)
 { // <------------------------------- add this
 potIn[i] = analogRead(pot[i]) / 8;
 // potentiometer could be too sensitive and
 // give different (+-1) values.
 // send CC only when the difference between last value
 // is more than 1
 if ((potIn[i] - lastAnalogValue[i]) > 1 || (potIn[i] - lastAnalogValue[i]) < -1) 
 {
 // value changed?
 if (potIn[i] != lastAnalogValue[i]) 
 {
 // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
 // more info: http://arduinomidilib.sourceforge.net/a00001.html
 MIDI.sendControlChange(1, potIn[i], 1);
 lastAnalogValue[i] = potIn[i];
 } // end of not same as before
 } // end of value changed
 } // <----------------- add this

If pot one is sending out Controller number 1 and channel number 1, 2nd pot should send Controller number 2 and channel no 2.

If I understand your question correctly:

Change:

MIDI.sendControlChange(1, potIn[i], 1);

to:

MIDI.sendControlChange(i, potIn[i], i);
answered Aug 26, 2015 at 20:55
7
  • Thanks Nick Gammon for the help..I am able to solve the input issue but I am still unable to send different MIDI messages through different input.. For ex if 1st pot is sending value 49 as expression value the next pot should send 50...like different expression value/channel message etc...in the increment of 1 Commented Aug 27, 2015 at 5:47
  • if 1st pot is sending value 49 as expression value - I'm sorry, I don't understand that. Commented Aug 27, 2015 at 5:51
  • I want to send values on different channels, or different controllers, instead of all on the same channel/controller.. Right now all the pots are sending out same Messages. I want different pots different messages.. Commented Aug 27, 2015 at 6:15
  • If pot one is sending out Controller number 1 and channel number 1, 2nd pot should send Controller number 2 and channel no 2.. Commented Aug 27, 2015 at 6:20
  • See amended answer. Commented Aug 27, 2015 at 9:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.