[dorkbotpdx-blabber] 5x5 matrix code help

Donald Delmar Davis ddelmardavis at gmail.com
Fri Mar 6 13:28:25 EST 2009


Dorkboard=mega168
On Mar 6, 2009, at 8:50 AM, Greg Grunest wrote:

> Hey,
> What board / chip are you using?
>
> Also, what are the exact errors?
>
> I tried your program and if I attempt to compile for an Arduino with  
> an Atmel 328, I get errors in line 51 & 52 of FrequencyTimer2.cpp.   
> I know why this is happening but I don’t know how to fix it  
> “elegantly”.  If this is your problem and you want my “kludge”, I’ll  
> send it to you.
>
> Original code from FrequencyTimer2.cpp
>
> 47: #if defined(__AVR_ATmega168__)
> 48:    if ( func) TIMSK2 |= _BV(OCIE2A);
> 49:    else TIMSK2 &= ~_BV(OCIE2A);
> 50: #else
> 51:    if ( func) TIMSK |= _BV(OCIE2);
> 52:    else TIMSK &= ~_BV(OCIE2);
> 53: #endif
>
> Or if another list reader has a good understanding of the inner  
> workings of the Arduino environment and cpp, maybe they could look  
> at it and spare me the shame of distributing a kludge. ;)
>
>
>
> Then, I tried to compile if for an Arduino with a 168 and I get  
> errors in stdlib.h line 111.  I looked at the line of code in  
> stdlib.h and I can’t see anything wrong with it.  Hmm…
>
> Stdlib.h:111
> /** The abs() function computes the absolute value of the integer \c  
> i.
>    \note The abs() and labs() functions are builtins of gcc.
> */
> extern int abs(int __i) __ATTR_CONST__;
>
>
> Then again, maybe you’re getting a completely different set of  
> errors.  It’s entirely possible.  So knowing what error you’re  
> getting and where would really help.
>
> - Greg
>
>
> From: dorkbotpdx-blabber-bounces at dorkbot.org [mailto:dorkbotpdx-blabber-bounces at dorkbot.org 
> ] On Behalf Of m sanders
> Sent: Thursday, March 05, 2009 9:40 PM
> To: dorkbotpdx-blabber at dorkbot.org
> Subject: [dorkbotpdx-blabber] 5x5 matrix code help
>
> 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
> }
>
> _______________________________________________
> dorkbotpdx-blabber mailing list
> dorkbotpdx-blabber at dorkbot.org
> http://music.columbia.edu/mailman/listinfo/dorkbotpdx-blabber

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/dorkbotpdx-blabber/attachments/20090306/f09fca09/attachment-0001.html


More information about the dorkbotpdx-blabber mailing list