Page 1 of 1

2 Lickogic + 2 Dilicktal

Posted: Mar 3rd, '14, 23:56
by riki
Hi,
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);
}





Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 4th, '14, 03:21
by e-licktronic
Dear riki,

Could you describe the problem you got. It will be easier to help you.


Best regards,
e-licktronic

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 5th, '14, 00:33
by riki
Hi,
thanks for the reply.

This is the code that I use for 2 Lickogic + 2 Dilicktal

But continues to send MIDI messages and LEDs stay on.
I changed the
"button_momentary" array
"byte pressed [16], just_pressed [16];"

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,2,4,6,8,10,12,14  }
  ,
  {
    1,3,5,7,9,11,13,15 }
};

boolean button_momentary_state;
byte last_button_momentary[8];
byte previous_button_momentary[8];


// 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 < 64; 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);
}


Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 14th, '14, 19:49
by riki
can somebody help me please?

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 19th, '14, 17:09
by e-licktronic
Dear riki,

The problem on your code is that you're checking the wrong Register: if (SR.Button_SR_Read(7) > 0 || SR.Button_SR_Read(6) > 0
If you only have two connected Dilicktal you couldn't check SR(7) and (6). you need to check SR(0) and (1).

If you got the last update of SRIO and Potmux libraries you don't need the constructors too.
Have a look on this code:
#include <SRIO.h>
#include <PotMUX.h>

//librairies constructors
//PotMUX Pot;
//SRIO SR;

// DEBUG mode 
#define DEBUG 1

//Number of connected potentiometers
#define NUMPOT 16

//communication mode 0=serial  1=MIDI  2=USB
#define COMMUNICATION_MODE 0
//Midi channel

#define MIDI_CHANNEL 1

//Pin number of the toggle button
byte button_toggle_Pin[]={
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};

boolean button_momentary_state;
byte last_button_momentary[8];
byte previous_button_momentary[8];


// 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<16;x++){
      SR.Led_Pin_Write (x,1);
      delay (40);
      SR.Led_Pin_Write (x-1,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(0) > 0 || SR.Button_SR_Read(1) > 0){
    for (byte i = 0; i < sizeof(button_toggle_Pin); i++){ //Scan as many time as toggle button
      if (just_pressed[button_toggle_Pin] ){ //pressed?
        count++; //if pressed count++
        switch (count)
        {
        case 1: // if counter ==1 Led "ON" and send MIDI message
          SR.Led_Pin_Write(button_toggle_Pin,1);
          Send_CC (button_toggle_Pin,127);
          break;
        case 2: // if counter ==2 Led "OFF" and send MIDI message
          SR.Led_Pin_Write(button_toggle_Pin,0);
          Send_CC (button_toggle_Pin,0);
          count = 0;   // initialize counter
          break;
        }
      }
    }
  }

  for (byte i=0; i<NUMPOT; i++){
    pot_Value = Pot.Read(i)>>3;//convert 10bits to 7bits
    if (abs (pot_Value - 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)
{
  if (DEBUG){
    Serial.print ("CC Nbr:");// "control change" message on selected MIDI_CHANNEL
    Serial.print (num_CC,DEC);
    Serial.print(" Value:");
    Serial.println (value,DEC);
  }
  else{

    Serial.write (176+MIDI_CHANNEL-1);// "control change" message on selected MIDI_CHANNEL
    Serial.write (num_CC);
    Serial.write (value);
  }
}


Best regards,
e-licktronic

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 19th, '14, 21:51
by riki
Hi,
thanks for the reply!

I've updated the library and I used the code you suggested, but I get this error in HairlessMIDI:

+2.507 - Error: got unexpected data byte 0x0.
+2.511 - Error: got unexpected data byte 0x0.
...
...

I work with mac 10.7.5
Thanks!

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 20th, '14, 05:53
by e-licktronic
Dear rikki,

You need to change DEBUG value by 0 and COMMUNICATION_MODE by 2.
Debug is use to print value in Arduino serial monitor. Have a look on Send_CC function.

Best regards,
e-licktronic

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 20th, '14, 09:20
by riki
Ok, sorry but I am a novice!
Thank you very much
Riki

Re: 2 Lickogic + 2 Dilicktal

Posted: Mar 20th, '14, 09:22
by e-licktronic
No problem ;)