I tried to use the sketch Ablickton_v1_0 to control 2 Lickogic + 2 Dilicktal, but I had some problems.
Can I find somewhere the code used in the video below?
http://www.youtube.com/watch?v=VAnYTYLGbg0[/video]
thanks
Riki
Code: Select all
#include <SRIO.h>
#include <PotMUX.h>
//librairies constructors
PotMUX Pot;
SRIO SR;
//Number of connected potentiometers
#define NUMPOT 16
//communication mode 0=serial 1=MIDI 2=USB
#define COMMUNICATION_MODE 2
//Midi channel
#define MIDI_CHANNEL 1
//Pin number of the toggle button
byte button_toggle_Pin[]={ };
//Array of the momentary button pin organize to match with Ableton clip configuration
uint8_t button_momentary[2][8]={
{
0,1,2,3,4,5,6,7 }
,
{
7,8,9,10,11,12,13,15 }
};
boolean button_momentary_state;
byte last_button_momentary[1];
byte previous_button_momentary[1];
// we will track if a button is just pressed, or 'currently pressed'
byte pressed[16], just_pressed[16];
// Simple count to remember the number of push of the toggle button
byte count[sizeof(button_toggle_Pin)]={
};
//potentiometers variables
uint32_t old_Pot_Value[NUMPOT];
uint32_t pot_Value[NUMPOT];
uint16_t buffer_pot_value[10];
//flag's mute button to be "ON" at start
boolean flag=1;
void setup()
{
SR.Initialize();//initialize SRIO librairy
Pot.Initialize();//initialize PotMUX librairy
switch (COMMUNICATION_MODE){
case 0:
Serial.begin(9600);
break;
case 1:
Serial.begin(31250);
break;
case 2:
Serial.begin(115200);
}
//Led animation start
for (byte x=0;x<2;x++){
for (byte i=0; i<7;i++){
SR.Led_Pin_Write (button_momentary[0][i],1);
SR.Led_Pin_Write (button_momentary[1][i],1);
delay (40);
SR.Led_Pin_Write (button_momentary[0][i-2],0);
SR.Led_Pin_Write (button_momentary[1][i-2],0);
}
for (byte i=7; i>0;i--){
SR.Led_Pin_Write (button_momentary[0][i-1],1);
SR.Led_Pin_Write (button_momentary[1][i-1],1);
delay (40);
SR.Led_Pin_Write (button_momentary[0][i+2],0);
SR.Led_Pin_Write (button_momentary[1][i+2],0);
}
}
SR.Led_All_Off();
}
void loop()
{
check_switches(); // when we check the switches we'll get the current state
if (SR.Button_SR_Read(7) > 0 || SR.Button_SR_Read(6) > 0 || flag==1 ){
for (byte i = 0; i < sizeof(button_toggle_Pin); i++){ //Scan as many time as toggle button
if (just_pressed[button_toggle_Pin[i]] || flag==1){ //pressed?
count[i]++; //if pressed count++
switch (count[i])
{
case 1: // if counter ==1 Led "ON" and send MIDI message
SR.Led_Pin_Write(button_toggle_Pin[i],1);
Send_CC (button_toggle_Pin[i],127);
break;
case 2: // if counter ==2 Led "OFF" and send MIDI message
SR.Led_Pin_Write(button_toggle_Pin[i],0);
Send_CC (button_toggle_Pin[i],0);
count[i] = 0; // initialize counter
break;
}
}
}
flag=0;
}
for(byte i =0;i<8;i++){
for(byte j=0;j<7;j++){
// button_momentary_state = SR.Button_Pin_Read(button_momentary[i][j]);
if(just_pressed[button_momentary[i][j]]){
last_button_momentary[i] = button_momentary[i][j];
if(last_button_momentary[i] != previous_button_momentary[i]){
SR.Led_Pin_Write(last_button_momentary[i],1);
Send_CC (last_button_momentary[i],127);
SR.Led_Pin_Write(previous_button_momentary[i],0);
previous_button_momentary[i]=last_button_momentary[i];
}
else{
Send_CC (last_button_momentary[i],127);
}
}
}
}
for (byte i=0; i<NUMPOT; i++){
pot_Value[i] = Pot.Read(i)>>3;//convert 10bits to 7bits
if (abs (pot_Value[i] - old_Pot_Value[i])>1){//value pot changed?
int data = map(pot_Value[i],3,123,0,127);// map to right midi value 0,127 due to the bad ADC and bad power stability
data=max(data,0);
data = constrain(data,0,127);
Send_CC (i+64,data);
old_Pot_Value[i] = pot_Value[i];
}
}
}
//-------------------------Funtions----------------------------------------
//Function that scan state of each button (code from Adafruit tutoriel)
void check_switches()
{
static byte previousstate[16];
static byte currentstate[16];
//Check switch en toggle Mode
for (byte index = 0; index < 16; index++){
just_pressed[index] = 0; // when we start, we clear out the "just" indicators
currentstate[index] = SR.Button_Pin_Read(index); // read the button
if (currentstate[index] == previousstate[index]){
if ((pressed[index] == LOW) && (currentstate[index] == HIGH)){
just_pressed[index] = 1;
}
pressed[index] = currentstate[index]; // remember, digital LOW means NOT pressed
}
previousstate[index] = currentstate[index]; // keep a states of the buttons
}
}
void Send_CC(byte num_CC, byte value)
{
Serial.write (176+MIDI_CHANNEL-1);// "control change" message on selected MIDI_CHANNEL
Serial.write (num_CC);
Serial.write (value);
}