I am having alot of trouble with the conways example to display on matrix. I am using Arduino mega328 and 0018 ide. It all compiles after editing the FrequencyTimer2, but nothing happens when I upload it to the arduino. I feel It is all connected up correctly, but this is what I have:
/*
* Conway's "Life"
*
* Adapted from the Life example
* on the Processing.org site
*
* Needs FrequencyTimer2 library
*/
#include "FrequencyTimer2.h"
byte col = 0;
byte leds[8][8];
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 10, 12, 15, 17, 11, 14, 16, 3, 13, 5, 7, 9, 2, 4, 6, 8};
// col[xx] of leds = pin yy on led matrix
int cols[8] = {pins[5], pins[6], pins[7], pins[8], pins[9], pins[10], pins[11], pins[12]};
// row[xx] of leds = pin yy on led matrix
int rows[8] = {pins[1], pins[2], pins[3], pins[4], pins[13], pins[14], pins[15], pins[16]};
#define DELAY 0
#define SIZE 8
extern byte leds[SIZE][SIZE];
byte world[SIZE][SIZE][2];
long density = 50;
void setup() {
setupLeds();
randomSeed(analogRead(5));
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (random(100) < density) {
world[i][j][0] = 1;
}
else {
world[i][j][0] = 0;
}
world[i][j][1] = 0;
}
}
}
void loop() {
// Display current generation
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
leds[i][j] = world[i][j][0];
}
}
delay(DELAY);
// Birth and death cycle
for (int x = 0; x < SIZE; x++) {
for (int y = 0; y < SIZE; y++) {
// Default is for cell to stay the same
world[x][y][1] = world[x][y][0];
int count = neighbours(x, y);
if (count == 3 && world[x][y][0] == 0) {
// A new cell is born
world[x][y][1] = 1;
}
if ((count < 2 || count > 3) && world[x][y][0] == 1) {
// Cell dies
world[x][y][1] = 0;
}
}
}
// Copy next generation into place
for (int x = 0; x < SIZE; x++) {
for (int y = 0; y < SIZE; y++) {
world[x][y][0] = world[x][y][1];
}
}
}
int neighbours(int x, int y) {
return world[(x + 1) % SIZE][y][0] +
world[x][(y + 1) % SIZE][0] +
world[(x + SIZE - 1) % SIZE][y][0] +
world[x][(y + SIZE - 1) % SIZE][0] +
world[(x + 1) % SIZE][(y + 1) % SIZE][0] +
world[(x + SIZE - 1) % SIZE][(y + 1) % SIZE][0] +
world[(x + SIZE - 1) % SIZE][(y + SIZE - 1) % SIZE][0] +
world[(x + 1) % SIZE][(y + SIZE - 1) % SIZE][0];
}
void setupLeds() {
// sets the pins as output
for (int i = 1; i <= 16; i++) {
pinMode(pins[i], OUTPUT);
}
// set up cols and rows
for (int i = 1; i <= 8; i++) {
digitalWrite(cols[i - 1], LOW);
}
for (int i = 1; i <= 8; i++) {
digitalWrite(rows[i - 1], LOW);
}
clearLeds();
// Turn off toggling of pin 11 and 3
FrequencyTimer2::disable();
// Set refresh rate (interrupt timeout period)
FrequencyTimer2::setPeriod(2000);
// Set interrupt routine to be called
FrequencyTimer2::setOnOverflow(display);
}
void clearLeds() {
// Clear display array
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds[i][j] = 0;
}
}
}
// Interrupt routine
void display() {
digitalWrite(cols[col], LOW); // Turn whole previous column off
col++;
if (col == 8) {
col = 0;
}
for (int row = 0; row < 8; row++) {
if (leds[col][7 - 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)
}
C:\Users\Randy\Desktop\Picture1.jpg
Arduino digital pin 0 - no connection
Arduino digital pin 1 - no connection
Arduino digital pin 2 - LED matrix pin #21
Arduino digital pin 3 - LED matrix pin #8
Arduino digital pin 4 - LED matrix pin #22
Arduino digital pin 5 - LED matrix pin #10
Arduino digital pin 6- LED matrix pin #23
Arduino digital pin 7 - LED matrix pin #11
Arduino digital pin 8 - LED matrix pin #24
Arduino digital pin 9 - LED matrix pin #12
Arduino digital pin 10 - LED matrix pin #1
Arduino digital pin 11 - LED matrix pin #5
Arduino digital pin 12 - LED matrix pin #2
Arduino digital pin 13 - LED matrix pin #9
Arduino digital pin 14 - LED matrix pin #6
Arduino digital pin 15 - LED matrix pin #3
Arduino digital pin 16 - LED matrix pin #7
Arduino digital pin 17 - LED matrix pin #4
Arduino digital pin 18 - no connection
Arduino digital pin 19 - no connection
link to the data sheet for the LED matrix :
My feeling is that it is something to do with the code as nothing is working. Thanks for help!