Go Down

Topic: Adding pots to my MIDI breath controller project (Read 537 times) previous topic - next topic



First of all I searched for an answer in this forum but did'nt find anything similar to my situation. I'm quite new to this, so maybe I'm not searching with the right keywords... anyways.

1. I want to add a potentiometer (knob) to select what CC message (what number) will be sent. The problem is, being a breath controller, I want toi choose between CC 1,2,7 and 11. If I use the map() function (ex:map(analogRead(A3),0,1023,1,11), I'd be able to select values between 1 and 11, but that's not what I want. How do I do to assign for example, pots values 0-255 to 1, 256-510 to 2, 511-768 to 7, 769-1023 to 11? In other words, how do I make a simple pot act like a 4 positions switch?

2. I want to add a sensitivity knob to control gain sensitivity (just like on a Yahama BC3).  How do I code this in the Arduino sketch? I have no clue...

3. last question; I added a simple gain knob (to add or remove gain on input). MIDI protocol being always from 0 to 127, what will happen if the breathInput + the gain knob value exceed 127? Will my VSTi or keyboard (or whater midi instrtument I control) just stop playing or it has a kind of ceiling at 127?

Arduino UNO;
10k pots;
a few 5mm LEDs...


1. If statements work well
2. I have no idea what that might be intended to do.
3. constrain(value, 0, 127) is a useful command to keep a values within the range 0-127.

OTOH I haven't looked at your code because the mobile device I'm using can't handle .ino files. If you had posted it as described in "How to use this forum" it would have helped.




1. First, thanks for your time. Here's the code.
2. The sensitivity knob I'm talking about is like the velocity sensitivity parameter that you can find on most midi keyboards. I think it modifies the velocity curve or something like that.
3. ok I'll try this, thx.

Code: [Select]

//include MIDI library... :
#include <MIDI.h>


int serialDebug = 0;
int breathInput = 0;
int LED_breathInput = 0;           
int MIDICH = 0;
int GAIN = 0;
int SIGLED_GAIN = 0;

int BI_offset = 0;          //--> BI=BreathInput

#define SIGLED 7                            //midi signal led
#define PROGLED 8                          //program ON led
#define MIDICHPOT A1                     //midi channel selector
#define GAINPOT A2                         //gain pot
//#define CCPOT A3                          //the CC pot I want ot add...
//#define SENSPOT A4                       //the gain sensitivity pot...
#define OFFSETPOT A5                       //velocity offset pot

void setup() {
  // put your setup code here, to run once:
  pinMode(SIGLED, OUTPUT);
  pinMode(GAINPOT, INPUT);
  digitalWrite(PROGLED, HIGH);           //just a led that shows that program is on
  digitalWrite(SIGLED, LOW);               //midi signal led is initially off

  if (serialDebug)

void loop()
  BI_offset = map(analogRead(A5),0,1023,0,127);                   
  breathInput = map(analogRead(A0),0+BI_offset,1023,0,127);       
  LED_breathInput = map(analogRead(A0),0,1023,0,255);             
  MIDICH = map(analogRead(A1),0,1023,1,16);                       
  GAIN = map(analogRead(A2),0,1023,-63,63);                       //add or remove velocity on input
  SIGLED_GAIN = map(analogRead(A2),0,1023,-127,127);       //same, but for signal led           

  analogWrite(7, LED_breathInput+SIGLED_GAIN);
  if (serialDebug)
    Serial.print("0 1023");                             
    if(breathInput >0)



Does that makes sense?

Code: [Select]

void loop()
  BI_offset = map(analogRead(A5), 0, 1023, 0, 127);                    
  breathInput = map(analogRead(A0), 0, 1023, 0, 127);                  
  LED_breathInput = map(analogRead(A0), 0, 1023, 0, 255);              
  MIDICH = map(analogRead(A1), 0, 1023, 1, 16);                      
  GAIN = map(analogRead(A2), 0, 1023, -63, 63);                        
  SIGLED_GAIN = map(analogRead(A2), 0, 1023, -127, 127);              
  CCPOT_input = map(analogRead(A3), 0, 1023, 1, 100);                  
  constrain(breathInput, BI_offset, 127);                              
  constrain(breathInput+GAIN, 0, 127);                                
  constrain(LED_breathInput+SIGLED_GAIN, 0, 255);                      

  analogWrite(7, LED_breathInput+SIGLED_GAIN);

//tentative de CC knob..
  if (CCPOT_input >0 <=25)
    int CC = 1;
  if (CCPOT_input >25 <=50)
    int CC = 2;
  if (CCPOT_input >50 <=75)
    int CC = 7;
  if (CCPOT_input >75 <=100)
    int CC = 11;


That's not how you write an if statement with multiple conditions. Try more like
Code: [Select]
  if (CCPOT_input >0 && CCPOT_input <=25)

And constrain only works on a single variable so you need to move breathInput+GAIN and LED_breathInput+SIGLED_GAIN into new variables and apply constrain to those.



I want toi choose between CC 1,2,7 and 11. If I use the map() function (ex:map(analogRead(A3),0,1023,1,11), I'd be able to select values between 1 and 11, but that's not what I want.

This is normally done with a switch/case statement, or it can be data-driven using an array to map an
index to one of the values:
Code: [Select]

byte CC_map[] = {1,2,7,11} ;
  CC_control = CC_map[index];
// or something like:

switch (index)
  case 0: return 1 ;
  case 1: return 2 ;
  case 2: return 7 ;
  case 3: return 11 ;

Why a pot though?  A rotary encoder would be the obvious choice for choosing discrete values as
they have detents.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


Thanks everyone for your answers. Really useful and I really appreciate!!

Go Up