bi color LED matrix with serial controll

i was looking for some ready to use program to control led matrix via serial console, so i could use it with my OpenWrt powered DockStar, but since i couldn't find any i wrote this:

/*
this program lets u to controll 8x8 bi color LED matrix (direct drive).
i'm using it to display email notifications, network stats etc.
arduino mega is connected to DockStar with OpenWrt no board.
it's cool addision for speach notificatins :D
just change pins to match your matrix and have fun ;)
*/
int pins[25]= {-1, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23};

int red[8] = {pins[23], pins[20], pins[17], pins[14], pins[2], pins[5], pins[8], pins[11]};
int green[8] = {pins[24], pins[21], pins[18], pins[15], pins[1], pins[4], pins[7], pins[10],};
int cols[8] = {pins[22], pins[19], pins[16], pins[13], pins[3], pins[6], pins[9], pins[12]};

void setup() {
  Serial.begin(9600);
  for (int i = 1; i <= 24; i++) {
    pinMode(pins[i], OUTPUT);
  }
}

int input;
int nowReadCol;
int nowReadRow;

int pattern[8][8] = { \
  {1, 1, 1, 1, 1, 1, 1, 1}, \
  {1, 2, 2, 2, 2, 2, 1, 1}, \
  {1, 2, 1, 1, 1, 1, 2, 1}, \
  {1, 2, 1, 1, 1, 1, 2, 1}, \
  {1, 2, 2, 2, 2, 2, 1, 1}, \
  {1, 2, 1, 1, 1, 1, 1, 1}, \
  {1, 2, 1, 1, 1, 1, 1, 1}, \
  {1, 1, 1, 1, 1, 1, 1, 1}
};

void loop() {
  show(pattern);
  inputS();  
}

void inputS() {
  //defined serial commands
  //we have 3 colors : red, greenand kinda-yellow
  //(r, g, y) and 0 as off
  //to change image on your matrix u have to define a line (A-H)and colors
  //so for example if u want to set 3rd line to Y-Y-G-G-R-R-OFF-OFF,
  //send 'Cyyggrr00'
  //if u wish to change only one pixel use something like 'D---r----'
  //'-' means "don't touch this LED" :D
  //send 'x' to turn off entire matrix
  //send 'N' to swap red and green LEDs
  if (Serial.available() > 0) {
    int input = Serial.read();
    switch (input) {
      case 'x':               //turn off entire natrix
        clean();
        break;
      case 'N':               //swap red with green pixels (entire matrix) 
        negative();
        break;
      case 'A':               //define row/collumn (depending on point of view :D )
        nowReadCol = 0;       // A-F => 1-8
        nowReadRow = 0;
        break;
      case 'B':    
        nowReadCol = 1;
        nowReadRow = 0;
        break;
      case 'C':    
        nowReadCol = 2;
        nowReadRow = 0;
        break;
      case 'D':    
        nowReadCol = 3;
        nowReadRow = 0;
        break;
      case 'E':    
        nowReadCol = 4;
        nowReadRow = 0;
        break;
      case 'F':    
        nowReadCol = 5;
        nowReadRow = 0;
        break;
      case 'G':    
        nowReadCol = 6;
        nowReadRow = 0;
        break;
      case 'H':    
        nowReadCol = 7;
        nowReadRow = 0;
        break;
      case 'r':                                //turn on red
        pattern[nowReadCol][nowReadRow] = 1;
        nowReadRow++;
        break;
      case 'g':                                //turn on green
        pattern[nowReadCol][nowReadRow] = 2;
        nowReadRow++;
        break;
      case 'y':                                //turn on yellow (red + green)
        pattern[nowReadCol][nowReadRow] = 3;
        nowReadRow++;
        break;
      case '0':                                //turn off
        pattern[nowReadCol][nowReadRow] = 0;
        nowReadRow++;
        break;
      case '-':                                //leave bit as is
        nowReadRow++;
        break;
    }
  }
}

void clean() {
  for (int kolumna = 0; kolumna < 8; kolumna++) {
    for (int wiersz = 0; wiersz < 8; wiersz++) {
      pattern[kolumna][wiersz] = 0;
    }
  }
}

void negative() {
  for (int kolumna = 0; kolumna < 8; kolumna++) {
    for (int wiersz = 0; wiersz < 8; wiersz++) {
      if (pattern[kolumna][wiersz] == 1) {
        pattern[kolumna][wiersz] = 2;
      }else{
        if (pattern[kolumna][wiersz] == 2) {
          pattern[kolumna][wiersz] = 1;
        }
      }
    }
  }
}

void show(int pattern[8][8]) {
  for (int kolumna = 0; kolumna < 8; kolumna++) {
    for (int wiersz = 0; wiersz < 8; wiersz++) {
      if (pattern[kolumna][wiersz] == 1) {
        digitalWrite(red[wiersz], LOW);
        digitalWrite(green[wiersz], HIGH);
      }
      if (pattern[kolumna][wiersz] == 2) {
        digitalWrite(green[wiersz], LOW);
        digitalWrite(red[wiersz], HIGH);
      }
      if (pattern[kolumna][wiersz] == 3) {
        digitalWrite(green[wiersz], LOW);
        digitalWrite(red[wiersz], LOW);
      }
      if (pattern[kolumna][wiersz] == 0) {
        digitalWrite(green[wiersz], HIGH);
        digitalWrite(red[wiersz], HIGH);
      }
    }
    digitalWrite(cols[kolumna], HIGH);
    delay(1);
    digitalWrite(cols[kolumna], LOW);
  }
}

i've made this for this matrix: http://www.artronic.pl/o_produkcie.php?id=757?

just very basic stuff, but u thought it might help someone :wink:
this is my first program for arduino (not including flashibg led lol) and i've never used C - php only and basic oncommodore64 years ago :D, so i'm sure it can b done way better.
anyways here it is :wink:

ps. 'kolumna' means column and 'wiersz' - row. that's polish. i forgot to translate that vars :smiley: