PotMUX library tutorial :
In this tutorial we will see how to use the library SRIO with Dilicktal Board
For this tutorial you need:
-1x Midilickuino
-1x Arduino
-1x à 6x Lickogic
-Arduino software (version 1.0 or newer)
-PotMUX_v1.1 library
-1x USB cable
PotMUX library description:
void Initialize();
// initalize PotMUX library
int Read (int number);
//Return 10bits value of selected potentiometer
//Equivalent to the function analog.Read()
//Number of potentiometer from 0 to 47
|
How to use PotMUX library:
Warning: The library SRIO only works with Arduino UNO, Pro, Duemilanove,
Diecimila, NG and Extreme because of PORT manipulation.
If you use an other Board have a look on the forum here or contact us and we will send you the code to your Arduino Board
1-You must copy the folder "PotMUX" located in Rar file library
PotMUX and paste it into the folder "libraries" of your Arduino environment
It is located in: X:/ .../arduino-1.0.x/libraries
You are now ready to use the library PotMUX.
2-We will now create a simple code that uses the PotMUX library functions
Launch Arduino and import our library
Go to "Sketch" then "Import Library ..." you should see PotMUX, click on it.
Followed by "void setup" and "void loop"
In "void setup" entry initialization function library: Pot.Initialize ()
Your code should look like the following:
#include <PotMUX.h>
void setup()
{
Pot.Initialize();
}
void loop()
{
}
|
3-Let have fun with the function
Connect Arduino to Midilickuino with Lickogic.
Jumper position corresponds with the number of potentiometers. If the jumper is set to 0
knobs are number 0 to 7, if it is 1, they are number 8 to 15 ...
4-We will create a program that will give us on the serial monitor of arduino
the value of a potentiometer and his number.
Here is the code and the comments so that you can understand how it works.
Upload the code and open the serial monitor by pressing CTRL + SHIFT + M
You should see a line that says: "The value of the potentiometer 0 is X".
/ / This code shows the number of potentiometer / / and its value
#include <PotMUX.h>
void setup()
{
//Initialize serial port at 9600 baud
Serial.begin(9600);
//Initialize PotMUX library
Pot.Initialize();
}
void loop()
{
//Send to the monitor the value of potentiometer 0
Serial.print("The value of the potentiometer 0 is ");
Serial.println(Pot.Read(0),DEC);
}
|
Move the knob and you will see its value changes from 0 to 1023.
5-A little exercise:
Try doing the same thing but this time, it is necessary that the serial monitor
does display the value only if you move the potentiometer.
You need to create two state variables of the potentiometer.
Here is the answer:
/ / This code shows the number of potentiometer / / and its value
#include <PotMUX.h>
//Variable of potentiometer value
int pot_value;
//variable who store old potentiometer value
int old_pot_value;
void setup()
{
//Initialize serial port at 9600 baud Serial.begin(9600);
//Initialize PotMUX library Pot.Initialize();
}
void loop()
{
//Store potentiometer value
pot_value = Pot.Read(0);
/*If the value has changed then displayed on the monitor is set to the new value Mathematical function is used to get an absolute margin between the new value and the old. This is due to the instability of the ADC*/
if(abs (old_pot_value - pot_value)>3)
{
//Send to the monitor the new value
Serial.print("The value of the potentiometer 0 is ");
Serial.println(pot_value,DEC);
//Don't forget to store the old value
old_pot_value = pot_value;
}
}
|
5-Now that we are familiar with the function, try to scan
our pots and return the value in the serial monitor.
you should use the Array and function "for".
Here is the code:
/ / This code shows the number of potentiometer / / and its value #include <PotMUX.h>
//Define number of potentiometer
#define NBR_POT 8
//Variable of potentiometer value
int pot_value;
//variable who store old potentiometer value
int old_pot_value;
void setup()
{
//Initialize serial port at 9600 baud Serial.begin(9600);
//Initialize PotMUX library Pot.Initialize();
}
void loop()
{
//loop as many as potentiometers
for(int i=0;i<NBR_POT;i++)
{
//Store value of each potentiometer
pot_value[i] = Pot.Read(i);
/*If the value has changed then displayed on the monitor is set to the new value Mathematical function is used to get an absolute margin between the new value and the old. This is due to the instability of the ADC*/
if(abs (old_pot_value[i] - pot_value[i])>3)
{
//Send to the monitor the new value and the number of the potentiometer
Serial.print("The value of the potentiometer ");
Serial.print(i,DEC);
Serial.print(" is ");
Serial.println(pot_value[i],DEC);
//Hold the old value
old_pot_value[i] = pot_value[i];
}
}
}
|
6-It only remains for us that created a function to send MIDI CC messages.
Convert our 10bits value to 7bit (because the value of a CC does not exceed 7 bits) and we
are ready to control what we want with our potentiometers
Here is the final code:
//This code send MIDI CC with potentiometer
#include <PotMUX.h>
//Define number of poteniometer
#define NBR_POT 8
//Define communication baudrate , 0=9600, 1=31250, 2=115200
#define SERIAL 2
//Variable of the value of the potentiometers
int pot_value[NBR_POT]={
};
//variable that hold the old value of the potentiometer
int old_pot_value[NBR_POT]={
};
//MIDI CC Function
void Send_CC(byte num_CC, byte value)
{
Serial.write (0xB0);//Message "control change" sur canal MIDI 1
Serial.write (num_CC);
Serial.write (value);
}
void setup()
{
//Choice baudrate
switch (SERIAL){
case 0:
Serial.begin(9600);//Communication serie pour le debuggage
break;
case 1:
Serial.begin(31250);//communication MIDI
break;
case 2:
Serial.begin(115200);//communication USB
break;
}
//Initialize PotMUX library
Pot.Initialize();
}
void loop()
{
//loop as many as potentiometers
for(int i=0;i<NBR_POT;i++)
{
//Store value of each potentiometer
pot_value[i] = Pot.Read(i);
/*If the value has changed then displayed on the monitor is set to the new value Mathematical function is used to get an absolute margin between the new value and the old. This is due to the instability of the ADC*/ if(abs (old_pot_value[i] - pot_value[i])>3)
{
//Send MIDI CC corresponding to the potentiometer number and value
Send_CC(i,pot_value[i]>>3);
//Hold the old value
old_pot_value[i] = pot_value[i];
}
}
}
|
Here we are at the end of this tutorial, have fun with all your buttons;).
Follow us