Go Down

Topic: How can I Define MIDI CC on multiplex (Read 517 times) previous topic - next topic

stuartdearden

Im pretty new to arduino and im building a MIDI controller. I can get all my potentiometers that are connected to the multiplex to work on one midi channel but was wondering if i could define them individually. ive used parts of other sketches in this but added my own to it

here is my sketch :

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();   // Create a MIDI instance

int r0 = 0;     
int r1 = 0;  // the three digital pins for the bits     
int r2 = 0;         

int value = 0; //value to read from multiplex
int midiValue = 0; // value devided to 0-127
int channel = 1;       // The message channel number
int controllerNumber = 1;   // The message controller number
int  bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//list of binary values
 
void setup(){
 
  pinMode(2, OUTPUT);    // r0
  pinMode(3, OUTPUT);    // r1
  pinMode(4, OUTPUT);    // r2
 
  Serial.begin(115200); // fire up the serial
}
 
 
void loop () {
   
 for (int count=0; count < 7; count++) { //loop through each channel, checking for a signal
   
   int row = bin[count];
   
   r0 = bitRead(row,0); //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
   r1 = bitRead(row,1); //channel 7 = 111, 1 = 2nd bit
   r2 = bitRead(row,2); // third bit
 
   digitalWrite(2, r0); // send the bits to the digital pins
   digitalWrite(3, r1);
   digitalWrite(4, r2);

   value = (analogRead(9));    // read the input pin
   midiValue = map (value,0,1023,0,127);
       
  // Serial.println(analogRead(9)); // after sending the binary sequence, the mux determines which channel to read from and sends it to this analog input

  MIDI.sendControlChange(controllerNumber, midiValue, channel);     // Send controller to the Hairless MIDI port
   
 }
 
 }


Grumpy_Mike

Quote
if i could define them individually
Do you mean each pot on a different channel?
Sure just set the channel number when you send the data. Using the variable count+1 should do it.

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

Go Up