Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
pizzaislife
Published © GPL3+

YOUR OWN SHAPE - 8x8 LED Matrix Arduino

Create your own shape without effort on an 8x8 LED Matrix using the code provided(easy to follow)

BeginnerFull instructions provided10,270
YOUR OWN SHAPE - 8x8 LED Matrix Arduino

Things used in this project

Story

Read more

Schematics

8x8 LED Matrix

The knob is at the bottom. which means pins 1-8 are there.

Code

CREATE YOUR OWN SHAPE 8x8 LED Matrix

C/C++
// 2-dimensional array of row pin numbers:
const int row[8] = {
  2, 7, 19, 5, 13, 18, 12, 16
};

// 2-dimensional array of column pin numbers:
const int col[8] = {
  6, 11, 10, 3, 17, 4, 8, 9
};

// 2-dimensional array of pixels:
int pixels[8][8];

typedef bool charMapType[8][8];

const charMapType heart = {
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 1, 1, 1, 1, 0},
  {0, 0, 1, 1, 1, 1, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0}
};

// angry robot
// const charMapType angryRobot = {
//   {1, 1, 1, 1, 1, 1, 1, 1},
//   {1, 0, 1, 1, 1, 1, 0, 1},
//   {1, 0, 0, 1, 1, 0, 0, 1},
//   {1, 1, 1, 1, 1, 1, 1, 1},
//   {1, 1, 0, 1, 1, 0, 1, 1},
//   {1, 0, 0, 0, 0, 0, 0, 1},
//   {1, 1, 1, 0, 0, 1, 1, 1},
//   {1, 1, 1, 1, 1, 1, 1, 1}
// };

//squares
// const charMapType squares = {
//   {1, 1, 1, 1, 1, 1, 1, 1},
//   {1, 0, 0, 0, 0, 0, 0, 1},
//   {1, 0, 1, 1, 1, 1, 0, 1},
//   {1, 0, 1, 0, 0, 1, 0, 1},
//   {1, 0, 1, 0, 0, 1, 0, 1},
//   {1, 0, 1, 1, 1, 1, 0, 1},
//   {1, 0, 0, 0, 0, 0, 0, 1},
//   {1, 1, 1, 1, 1, 1, 1, 1}
// };

void setup() {
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);
  }
  setupMatrix();
}

void loop() {
  displayLedPattern();
}

void displayLedPattern(){
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    digitalWrite(row[thisRow], HIGH);
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}

void setupMatrix(){
  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      bool v = squares[x][y];
      if(v){
        pixels[x][y] = LOW;
      }else{
        pixels[x][y] = HIGH;
      }
    }
  }
}

Credits

pizzaislife
0 projects • 0 followers

Comments