Go Down

Topic: Audio Matrix project (Read 1 time) previous topic - next topic

rrowley

Hi
I'm looking for some help or for someone to write the code for an audio matrix project.I'm experienced building synthesizers,amplifiers and designing pcb's but quite new to programming so would be grateful for any advice on
1) which arduino should I use
2) how best to approach coding

This is the patch matrix of an EMS VCS3 synthesizer.The outputs of the modules(left) are connected to the inputs(top) by a 2 pole jack pin completing the circuit.Nice and simple.



and this is what I'd like to make using 4 8x8 led matrix driven by MAX 7221 and 32 ADG 1414 octal switches.All controlled via SPI.




So far I have a LED matrix/7221 working with a joystick controller to select an individual pixel but that's it so far.

I'm having trouble finding an example of using push switches(up down left right) to select the required pixel.I'd like to be able to press the write button and the pixel in row 1,column 1 would flash.Then use the direction buttons to select eg row 5,column 10.Press write again and the led stops flashing and stays on indicating the connection at that point is made.

Whichever LED is on also needs to activate the corresponding switch on the ADG1414
Here's the datasheet and the relevent details

http://www.analog.com/media/en/technical-documentation/data-sheets/ADG1414.pdf



I'd like to write the code but I'm still in the looking at examples to see how it works stage but as I said I can't find any.

The memory button and usb on my mockup are hopefully to include patch memory store/recall on the arduino and midi recall but for now would be happy just selecting pixels.

Any help,ideas or coding(paid) appreciated

Rich

bobcousins

That looks pretty straightforward, I think it would not take long to write. I'd probably use an Uno, but any mega328 would do I think.

Implementing a USB drive is a whole chunk of work, you'll need a USB host controller and FATFS code, but both of those are available.
Please ask questions in the forum so everyone can benefit. PM me for paid work.

wildbill

Quote
So far I have a LED matrix/7221 working with a joystick controller to select an individual pixel
Posting the code that does this would be helpful.

rrowley

I'll definately be leaving the memory/usb stuff till last.I know I'm trying to run before walking :)

The code I've found is nearly there in that I can select a pixel but the joystick button just turns the matrix off.I need to find out how to select a pixel,press the button and have it remain lit.
I'm working my way through Begining C for Arduino by Jack Purdum so hopefully that will help.





Code: [Select]
/* This sketch detects analog signals from the potentiometers
within the joystick and sends it to the serial monitor */

//initialize variable for x and y values on the joystick and the pushbutton at digital pin 4
int UD;
int LR ;
int button=4;

#include "LedControl.h" //  importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc=LedControl(10,12,11,0);

void setup() {
  Serial.begin(9600);
  lc.shutdown(0,false);// turn off power saving, enables display
  lc.setIntensity(0,8);// sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  pinMode(button, INPUT); // button is input
  digitalWrite(button, HIGH); // initalize button as ON 

}

void loop() {
  UD = analogRead(A1); // read analog value at pin A1 and stores as UD
  LR = analogRead(A0);  // read analog value at pin A0 and stores as LR
  int state=digitalRead(button); //determines the state of button (HIGH or LOW)
  // scales down the value from 0-1023 to 0-7
  char x_translate = map(LR, 0,1023, 7, 0);
  char y_translate = map(UD, 0,1023, 7, 0);

  Serial.print ("Button=");
  Serial.print(state, DEC);
  Serial.print(", UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);
 
    // clears display whenever a new value is updated
    lc.clearDisplay(0);
    lc.setLed(0,x_translate,y_translate,true); 
    // if button is pressed, LED is OFF and vice versa
    if (state==1){
    lc.setLed(0,x_translate,y_translate,true);
    }
    else {
    lc.setLed(0,x_translate,y_translate,false);
    }
   
  delay(100); //Mess with delay to tweak accuracy
}

bobcousins

So I think you are showing the location of the joystick by lighting a pixel, then using the button to store it?

This is a standard graphics problem. The joystick is like the mouse cursor, and the stored position are like a background window.

What I would do is keep an array of pixels that have been stored. Then when you move the joystick, restore the last location to the stored value, and set the new location on (but don't store it).

Code: [Select]

/* This sketch detects analog signals from the potentiometers
  within the joystick and sends it to the serial monitor */

//initialize variable for x and y values on the joystick and the pushbutton at digital pin 4
int UD;
int LR ;
int button = 4;

bool stored_state [8][8];

int last_x, last_y;

#include "LedControl.h" //  importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc = LedControl(10, 12, 11, 0);

void setup() {
  Serial.begin(9600);
  lc.shutdown(0, false); // turn off power saving, enables display
  lc.setIntensity(0, 8); // sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  pinMode(button, INPUT); // button is input
  digitalWrite(button, HIGH); // initalize button as ON

}

void loop() {
  UD = analogRead(A1); // read analog value at pin A1 and stores as UD
  LR = analogRead(A0);  // read analog value at pin A0 and stores as LR
  int state = digitalRead(button); //determines the state of button (HIGH or LOW)
  // scales down the value from 0-1023 to 0-7
  char x_translate = map(LR, 0, 1023, 7, 0);
  char y_translate = map(UD, 0, 1023, 7, 0);

  if ( (last_x != x_translate) || (last_y != y_translate) )
  {
    // the position has moved so we need to restore previous state
    lc.setLed(0, last_x, last_y, stored_state [last_x][last_y] );
  }

  last_x = x_translate;
  last_y = y_translate;

  Serial.print ("Button=");
  Serial.print(state, DEC);
  Serial.print(", UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);

  // clears display whenever a new value is updated
  /// --> dont do this!  lc.clearDisplay(0);

  // just set led in new joystick position
  lc.setLed(0, x_translate, y_translate, true);
 
  // if button is pressed, store it
  if (state == 1) {
    stored_state [last_x][last_y] = true;
  }

  delay(100); //Mess with delay to tweak accuracy
}
Please ask questions in the forum so everyone can benefit. PM me for paid work.

rrowley

That's great.Exactly what I was looking for.Thanks
I'm now using two pots instead of the joystick.Much easier to control.
So now I can select a pixel but I also need to deselect a previously selected pixel.
I've edited the code to add another button to deselect by copying the original button code and changing the name and pin but this doesn't work as i'm getting a redeclaration of 'int state' error at line 37.
Would this work in theory or is there a better approach?


Code: [Select]
/* This sketch detects analog signals from the potentiometers
  within the joystick and sends it to the serial monitor */

//initialize variable for x and y values on the joystick and the pushbuttons at digital pin 4 and 7
int UD;
int LR ;
int button_a = 4;
int button_b = 7;


bool stored_state [8][8];

int last_x, last_y;

#include "LedControl.h" //  importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc = LedControl(10, 12, 11, 0);

void setup() {
  Serial.begin(9600);
  lc.shutdown(0, false); // turn off power saving, enables display
  lc.setIntensity(0, 8); // sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  pinMode(button_a, INPUT); // button is input
  digitalWrite(button_a, HIGH); // initalize button as ON
  pinMode(button_b, INPUT); // button is input
  digitalWrite(button_b, HIGH); // initalize button as ON


}

void loop() {
  UD = analogRead(A1); // read analog value at pin A1 and stores as UD
  LR = analogRead(A0);  // read analog value at pin A0 and stores as LR
  int state = digitalRead(button_a); //determines the state of button_a (HIGH or LOW)
  int state = digitalRead(button_b); //determines the state of button_b (HIGH or LOW)
  // scales down the value from 0-1023 to 0-7
  char x_translate = map(LR, 0, 1023, 7, 0);
  char y_translate = map(UD, 0, 1023, 0, 7);

  if ( (last_x != x_translate) || (last_y != y_translate) )
  {
    // the position has moved so we need to restore previous state
    lc.setLed(0, last_x, last_y, stored_state [last_x][last_y] );
  }

  last_x = x_translate;
  last_y = y_translate;

  Serial.print ("Button_a=");
  Serial.print ("Button_b=");
  Serial.print(state, DEC);
  Serial.print(", UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);

  // clears display whenever a new value is updated
  /// --> dont do this!  lc.clearDisplay(0);

  // just set led in new joystick position
  lc.setLed(0, x_translate, y_translate, true);
 
  // if button_a is pressed, store it
  if (state == 0) {
    stored_state [last_x][last_y] = true
    ;
  }

// if button_b is pressed, delete it
  if (state == 1) {
    stored_state [last_x][last_y] = true
    ;
  }
 
  delay(150); //Mess with delay to tweak accuracy
}


wildbill

I would use one button & just toggle the led between on & off with each press. To get your two button working though, you need two state variables with different names. Here's how it might look:
Code: [Select]

/* This sketch detects analog signals from the potentiometers
  within the joystick and sends it to the serial monitor */

//initialize variable for x and y values on the joystick and the pushbuttons at digital pin 4 and 7
int UD;
int LR ;
int button_a = 4;
int button_b = 7;


bool stored_state [8][8];

int last_x, last_y;

#include "LedControl.h" //  importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc = LedControl(10, 12, 11, 0);

void setup() {
  Serial.begin(9600);
  lc.shutdown(0, false); // turn off power saving, enables display
  lc.setIntensity(0, 8); // sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
  pinMode(button_a, INPUT); // button is input
  digitalWrite(button_a, HIGH); // initalize button as ON
  pinMode(button_b, INPUT); // button is input
  digitalWrite(button_b, HIGH); // initalize button as ON


}

void loop() {
  UD = analogRead(A1); // read analog value at pin A1 and stores as UD
  LR = analogRead(A0);  // read analog value at pin A0 and stores as LR
  int stateA = digitalRead(button_a); //determines the state of button_a (HIGH or LOW)
  int stateB = digitalRead(button_b); //determines the state of button_b (HIGH or LOW)
  // scales down the value from 0-1023 to 0-7
  char x_translate = map(LR, 0, 1023, 7, 0);
  char y_translate = map(UD, 0, 1023, 0, 7);

  if ( (last_x != x_translate) || (last_y != y_translate) )
  {
    // the position has moved so we need to restore previous state
    lc.setLed(0, last_x, last_y, stored_state [last_x][last_y] );
  }

  last_x = x_translate;
  last_y = y_translate;

  Serial.print ("Button_a=");
  Serial.print(stateA, DEC);
  Serial.print ("Button_b=");
  Serial.print(stateB, DEC);
  Serial.print(", UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);

  // clears display whenever a new value is updated
  /// --> dont do this!  lc.clearDisplay(0);

  // just set led in new joystick position
  lc.setLed(0, x_translate, y_translate, true);

  // if button_a is pressed, store it
  if (stateA == 0) {
    stored_state [last_x][last_y] = true;
  }

  // if button_b is pressed, delete it
  if (stateB == 1) {
    stored_state [last_x][last_y] = false;
  }

  delay(150); //Mess with delay to tweak accuracy
}

Compiled, not tested.

rrowley

Great that worked a treat.Thanks.All I had to do was change the button_b state to 0.
Now I need to do some reasearch to find out how to associate a lit pixel with a closed switch of an ADG1414.

wildbill

Associating the pixel data with the switches is just a matter of reading the data out of your array and using bit twiddling operations to get it into a state to send to your ADG1414s.

Before that though, I'd suggest that you establish that you can control the octal latches, presumably through SPI. Once you can do that, folks here can help you with the bit manipulations.

rrowley


rrowley

I've run into a problem.While waiting for my ADG1414 switches to arrive I hooked up the other 3 8x8 led matrix/7219 to get my 16x16.I've daisy chained them in all posible combinations of linking the DIN to DOUT but only one matrix works correctly.The second matrix just duplicates what I see on the first and the third and fouth are blank.They all test good when using only one matrix.
I've edited the sketch to select 4 matrices(3) and changed the translate values from 0-7 to 0-15 but it seems stuck in 8x8 mode.
Wondering what I've missed here.Do I need to edit the Ledcontrol library?

bobcousins

I've edited the sketch to select 4 matrices(3) and changed the translate values from 0-7 to 0-15 but it seems stuck in 8x8 mode.
There was a bug in your first code, numDevices should be 4 if you have 4 devices.
Quote
* numDevices   maximum number of devices that can be controled
         */
        LedControl(int dataPin, int clkPin, int csPin, int numDevices=1);
LedControl library does not map pixels across devices, it does not know the layout. You will need to calculate the device address from the X,Y coord, and also pass the coords modulo 8.

If the devices are arranged
  1   2
  3   4

then
address = (x_translate/8) + (y_translate/8)*2
x = x_translate % 8
y = y_translate % 8
Please ask questions in the forum so everyone can benefit. PM me for paid work.

rrowley

I actually had the device number set to 3 for some reason.Now set to 4.

I'm not sure how to incorporate this example into my sketch?


then
address = (x_translate/8) + (y_translate/8)*2
x = x_translate % 8
y = y_translate % 8

rrowley

Still a bit stuck with this.The sketch works great for selecting leds on one matrix(8x8) but needs to be a 16x16
Any help appreciated

Go Up