# 4x5 Relatively Prime LED Matrix

1,388

1

Published

## Introduction: 4x5 Relatively Prime LED Matrix

I did this project as a final for Physics Lab 308L at the University of New Mexico.  All semester long I got tons of help from Steve Koch and Anthony Salvagno.

The influence for this project came from an image I saw in a Number Theory course.  You can create a large lattice (or "checker board" if you will) and shade in the square if the two corresponding numbers are relatively prime (gcd=1) and leave the square blank if the two numbers share a common factor.  Doing this produces a really cool image, that I have attached below.

In order to see the beauty of the effect, you really would need to make a 50x50 or a 100x100 LED matrix, but I just simply didn't have the resources to do that.  All I could afford to make was a 4x5 matrix.  Yes, I know, the visualization is not that profound but my hope is that putting this project up here, will inspire someone with more resources to make a huge matrix.  My code can be easily adapted and maybe by using more Arduinos, this can be done fairly easily.

My materials weren't anything that couldn't be found in most electronics labs:

--  One Arduino Uno
--  4 400 Ohm resistors
--  20 LEDs
--  4 Proto-boards (or a very large breadboard would do the trick as well)
--  Lot's of wire

## Step 1: Wiring

The wiring for this project is not terribly difficult, it just involves some hard wiring under the LEDs.  There is not much to be said, I have uploaded three pictures from different angles to show how the wiring works.

## Step 2: Code

byte PATTERN[][5] = {
{B1111,
B1010,
B1101,
B1010,
B1111,},
};

int ROW_PINS[] = {13, 12, 11, 10, 9};
int COL_PINS[] = {5, 4, 3, 2};

#define ROW_COUNT (5)
#define COL_COUNT (4)
#define PATTERN_DELAY_MS (3000)
#define MULTIPLEX_DELAY_MS (3)

void setup(){
int pinset=0;
Serial.begin(9600);
for (pinset=0;pinset<ROW_COUNT;pinset++){
pinMode (ROW_PINS[pinset],OUTPUT);
}
for (pinset=0;pinset<COL_COUNT;pinset++){
pinMode (COL_PINS[pinset],OUTPUT);
}
}

void loop() {
ShowPattern(PATTERN[0]);
}

void SetColumn(byte pattern) {
for (int i = COL_COUNT-1; i >= 0; i--, pattern >>= 1) {
digitalWrite(COL_PINS[i], pattern & 1 ? LOW : HIGH);
}
}

void ShowPattern(byte pattern[]) {
int last_row = ROW_COUNT-1;
for (int row = 0; row < ROW_COUNT; last_row = row++) {
digitalWrite(ROW_PINS[row], HIGH);
digitalWrite(ROW_PINS[last_row], LOW);
SetColumn(pattern[row]);
delay(MULTIPLEX_DELAY_MS);
}
}

Once this code is unloaded and verified, the arduino should power the LED matrix properly.  For some reason, I couldn't get Instructables to upload my video, but it is on YouTube.  The link is :http://www.youtube.com/watch?v=BJLpog_lnj0&feature=youtu.be

(Sorry for the poor quality of the video.)

## Recommendations

• ### Large Motors Class

8,825 Enrolled

• ### Planter Challenge

We have a be nice policy.