Go Down

Topic: Sending matrix Values from Max/Msp to Arduino to control 3 x 3 LED matrix (Read 498 times) previous topic - next topic

diesIrae

I'm currently working on my second project working with arduino, and have been having trouble getting my prototype to work. The goal is to have dynamic control over around 180 multiplexed LEDs, and then to create algorithmic behaviours for the led's. All of the behaviours are being coded in Max, and all I want arduino to do is control the lighting of LEDs.

Right now I'm working in a 3x3 grid (with the anodes of led's connected in columns, and the cathodes in rows). I would like to send cell-data from Max in the form of [0, 0, 0] //column(0 to 2), row(0 to 2), state(0 or 1). Then I would like arduino to write them into a state array table, and figure out how to light them up. My current code works to light up individual led's correctly, but I am getting unwanted led's lighting up when I have multiple turned on. I was hoping that there would be a straight forward answer to this problem that would avoid IC chips, but I do have some 74HC595 handy. Any help would be greatly appreciated, thanks!

ex)

The states:     Would also cause:      The states:    Would also cause:       But:
     0 1 0              X 1 0                       1 0 0            1 0 X                      1 0 0
     1 0 0              1 0 0                       0 1 0            0 1 X                      0 1 0
     0 0 0              0 0 0                       0 0 1            X 0 1                      0 0 0  would work fine...
                                     
This is my code:
Code: [Select]

const int numCols = 3;
const int numRows = 3;
const int colPins[numCols] = {2,3,4}; //column pins
const int rowPins[numRows] = {5,6,7}; //row pins

boolean state[numRows][numCols] = {
  {0,0,0},
  {0,0,0},
  {0,0,0}
};

void setup()
{
 
    Serial.begin(57600);
   
    //setup pins
    for (int column = 0; column < numCols; column++)
    {
      pinMode(colPins[column], OUTPUT);
      digitalWrite(colPins[column],LOW);
    }
   
    for (int row = 0; row < numRows; row++)
    {
      pinMode(rowPins[row], OUTPUT);
      digitalWrite(rowPins[row],LOW);
    }     
}


void loop()
{
   
  getCellData();
  lightUp();

}

void getCellData()
{
 
  //get chunk of three numbers, corresponding to matrixctl cell, row, and state
  if (Serial.available() == 3)
  {
    char a = Serial.read();
    char b = Serial.read();
    char c = Serial.read();
   
    //write data to state array table
    state[a][b] = c;
  }
 
}

void lightUp()
{
  for (int row = 0; row < numRows; row++)
    for (int column = 0; column < numCols; column++) {
      if (state[row][column]) {
        digitalWrite(colPins[column],LOW);
        digitalWrite(rowPins[row],HIGH);
      }
      else {
        digitalWrite(colPins[column],HIGH);
        digitalWrite(rowPins[row],LOW);
      }
    }
}

CrossRoads

Don't you need to these chars into numbers?

    char a = Serial.read();
    char b = Serial.read();
    char c = Serial.read();

see www.asciitable.com
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up