[dorkbotpdx-blabber] 5x5 matrix code help

m sanders modularduck at yahoo.com
Fri Mar 6 00:39:35 EST 2009


Hey all, so i am new to the whole cult thing and am needing some help with some code i am tryin to adapt from the arduino site to make this 5x5 matrix work directly off dork board problem is that there are errors and im not savvy enough with programming to work it out, more of a production kinda guy not so much a software kinda guy. anyway i digress and will thank you all in advance for any help you might be about to give me. 

michael

here is code. also as a side not you can seei jusr shortened the defined space and changed row and column things to reflec the size of my matrix. there is a part in the code that speaks of pin 11 and i am not using it so maybe thats one problem but, the error messages have no mention of this, and i have installed all libraries in the correct locations and everything. or anyone have some 5x5 code layin around? thanks again!

/*
 * Show messages on an 5x5 led matrix,
 * scrolling from right to left.
 * 
 * Uses FrequencyTimer2 library to
 * constantly run an interrupt routine
 * at a specified frequency. This
 * refreshes the display without the
 * main loop having to do anything.
 *
 */

#include <FrequencyTimer2.h>

#define SPACE { \
    {0, 0, 0, 0, 0},  \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
  
}

#define H { \
    {1, 0, 0, 0, 1}, \
    {1, 0, 0, 0, 1}, \
    {1, 1, 1, 1, 1}, \
    {1, 0, 0, 0, 1}, \
    {1, 0, 0, 0, 1}, \
    
}

#define E  { \
    {1, 1, 1, 1, 1}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 1, 1}, \
    
}

#define L { \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 1, 1}, \
    
}

#define O { \
    {0, 1, 1, 1, 0}, \
    {1, 0, 0, 0, 1}, \
    {1, 0, 0, 0, 1}, \
    {1, 0, 0, 0, 1}, \
    {0, 1, 1, 1, 0}, \
    
}

byte col = 0;
byte leds[5][5];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[11]= {-1, 4, 3, 14, 17, 13, 12, 10, 9, 8, 6};

// col[xx] of leds = pin yy on led matrix
int cols[5] = {pins[13], pins[3], pins[4], pins[10], pins[06]};

// row[xx] of leds = pin yy on led matrix
int rows[5] = {pins[9], pins[14], pins[8], pins[12], pins[1]};

const int numPatterns = 6;
byte patterns[numPatterns][5][5] = {
  H,E,L,L,O,SPACE
};

int pattern = 0;

void setup() {
  // sets the pins as output
  for (int i = 1; i <= 10; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 5; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 5; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop() {
    pattern = ++pattern % numPatterns;
    slidePattern(pattern, 60);
}

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      leds[i][j] = patterns[pattern][i][j];
    }
  }
}

void slidePattern(int pattern, int del) {
  for (int l = 0; l < 5; l++) {
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 5; j++) {
        leds[j][i] = leds[j][i+1];
      }
    }
    for (int j = 0; j < 5; j++) {
      leds[j][4] = patterns[pattern][j][0 + l];
    }
    delay(del);
  }
}

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 5) {
    col = 0;
  }
  for (int row = 0; row < 5; row++) {
    if (leds[col][4 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
  delayMicroseconds(900);  // Delay so that on times are longer than off time = brighter leds
}


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/dorkbotpdx-blabber/attachments/20090305/31b4f1fe/attachment.html


More information about the dorkbotpdx-blabber mailing list