Friday, May 10, 2013

Getting wired...

So I attached the LED board across 2 breadboards. You can see the first tiny breadboard peaking out from under the front of the array.  It had 17 rows and, yes, the matrix only needed 16. I verified where pin 1 was and ran leads from each pin to the matching pin on the Arduino board.
It's a thing of beauty, is it not? Now down to business, I have to match up the pins to the rows, columns, and colors for my first sketch. Carefully going through the schematic, I came up with:

int colsr[]={9,10,11,12,13,14,15,16}; //red
int colsg[]={28,27,26,25,24,23,22,21}; //green
int colsb[]={1,2,3,4,5,6,7,8}; //blue
int rows[]={17,18,19,20,29,30,31,32};

I'll have to come up with a little more eloquent method, but this will do to get some lights lit up. Again, referring to the schematic, I see that the LEDs are oriented so that the power is coming from the rows, so the colors/columns are specified by the ground pins. This seems backward to me since, at some point, I'm going to want to write different values to the pins to blend colors instead of just setting them to HIGH.

Next, I created my setup() routine. Here I need to initialize all of the pins for output and set their initial state.

void setup() {
  // put your setup code here, to run once:
   for(int pin=1;pin<=32;pin++){
     pinMode(pin,OUTPUT);
   }
   for(int idx=1;idx<=9;idx++){
     digitalWrite(colsr[idx-1],HIGH);
     digitalWrite(colsg[idx-1],HIGH);
     digitalWrite(colsb[idx-1],HIGH);
     digitalWrite(rows[idx-1],LOW);
   }
}
Since the columns are supposed to be grounds, I chose to set them to the opposite state, so I raised them to HIGH, and the rows, I set to LOW. Makes sense, right? My loop is pretty straight forward. I want to turn on pin 1, row 1, turn it off, then pin 2, row 2, etc. What I ended up with was a pattern, of 1 sometimes 2 LEDs lighting up in each column, but after running for a bit, other LEDs lit and stayed on. Now comes the fun part. Is it my code, or my wiring, or both. I'll keep you posted.

No comments:

Post a Comment