loading

Hi. This is my first instructable so hopefully you will like it. My LED Matrix Console started off as finding out how cool led matrices were. Then i bought some parts and soldered them together and it worked!

The pictures are of the console at the moment, I hope to create a case for it in the future.

Step 1: Things You Will Need:

  1. Adafruit Flora Board - This is the main device £20
  2. Adadfruit LED Matrix board - I chose the 8x16 one, Find out more on their website - £16?
  3. Buttons - I just took some momentary switches off an old radio - FREE
  4. Joystick - I had this one laying around but you can take them out of old game controllers and stuff - FREE
  5. Battery - I took a 570mAh 3.7v battery from an old ps3 controller
  6. Adafruit USB charging board - This is used to charge the battery - £5-10
  7. Wire and basic soldering skills

Step 2: Assembly

  • Start by connecting the GND,SCL,SDA,3.3V from the Flora board to the LED matrix (SCL - SCL, SDA - SDA)
  • Connect the buttons (2 for me) to the Flora board pins and ground. Make sure you leave 2 of pins 10,9,6 and 12 free so you can connect the joystick to the analog pins. (Remember you can connect to pin RX as D0 and TX as D1)
  • Now connect the joystick to the Flora board. +pin to 3.3v, - to gnd, and the two other pins to any 2 of these pins on the flora, 10,9,6,12.(These are analog pins.)
  • Finally add a switch between the battery and the flora an you're good to go.
  • If you want to add the charger in then you could make a circuit for it or just unplug the battery and connect it to the charger.

Step 3: Programming

To program the the Flora board you head over to the Adafruit Tutorial on using Flora with the IDE and this will help you to program the board.

You will need to install the Adafruit_GFX library and the Adafruit_LEDBackpack library and then you're good to go programming. I also used the Timer library in my project.

Once you have installed the libraries under their examples find you're LED matrix and start changing the code around.

My code(BELOW) includes a space invaders game and some other things...It is not complete as yet but gives you and understanding of how it works.

#include
#include "Adafruit_LEDBackpack.h" #include "Adafruit_GFX.h" #include "Timer.h"

Adafruit_8x16matrix matrix = Adafruit_8x16matrix(); // the timer object Timer t; Timer b1; Timer b2; Timer b3; Timer b4; Timer d;

// Button Pins int MENUBUTTON = 12; int SPECIALBUTTON = 6; int Dbutton = 150;

int JOYUD = 9; int JOYLR = 10; int value1 = 0; int value2 = 0; int value3 = 0; int value4 = 0;

boolean mainmenu; int menupage;

int game = 0;

// Game 1 int game1playerscore; int targety = 8; int targetx; int targetx1; int targetx2; int targetx3; int targetx4; int targetx5; int targety1 = 8; int targety2 = 8; int targety3 = 8; int gunpos = 7; boolean GAME1OVER; int bulletpos; boolean shoot1;

// Game 2 int paddleX; int ballX; int ballY; boolean ballup = false; int balldirection; int game2score; int game2level; int ballspeed = 600; int fencecounter;

int linelength = 5; int lineSTART = 1; boolean lineDIR = true; int lineHEIGHT = 1; int line1; int line2; int line3; int line4;

void gameover(){ }

void linemove(){ if(lineDIR == true){ lineSTART--; } else if(lineDIR == false){ lineSTART++; } }

void targetdown() { //Drop target down targety--; targety1--; targety2--; targety3--; }

void drawpaddle(){ matrix.drawPixel(paddleX,0,LED_ON); matrix.drawPixel(paddleX + 1,0,LED_ON); } void drawball(){ matrix.drawPixel(ballX,ballY,LED_ON); } void ballmove(){ // Move ball up/down if(ballY < 7 && ballup == true){ ballY++; } else if(ballY > -1 && ballup == false){ ballY--; } // Move ball Left/Right if(balldirection == 1 && ballX < 15){ ballX--; } else if(balldirection == 1 && ballX > 0){ ballX--; } else if(balldirection == 3 && ballX < 7){ ballX++; } else if(balldirection == 3 && ballX > 0){ ballX++; } }

void drawscore2(){ if(game2score < 4){ game2level = 1; } if(game2score >= 4){ matrix.drawLine(15,0, 15,7, LED_ON); game2level = 1; } if(game2score >= 8){ matrix.drawLine(14,0, 14,7, LED_ON); game2level = 2; } if(game2score >= 14){ matrix.drawLine(13,0, 13,7, LED_ON); game2level = 3; } if(game2score >= 20){ matrix.drawLine(12,0, 12,7, LED_ON); game2level = 4; } if(game2score >= 27){ matrix.drawLine(11,0, 11,7, LED_ON); game2level = 5; } if(game2score >= 35){ matrix.drawLine(10,0, 10,7, LED_ON); game2level = 6; } if(game2score >= 45){ matrix.drawLine(9,0, 9,7, LED_ON); game2level = 7; } if(game2score >= 60){ matrix.drawLine(8,0, 8,7, LED_ON); game2level = 8; } } int treatValue(int data) { return (data * 9 / 1024) + 48; }

void setup() { Serial.begin(9600); matrix.begin(0x70); // pass in the address t.every(1000,targetdown); b1.every(300,ballmove); b2.every(200,ballmove); b3.every(150,ballmove); b4.every(100,ballmove); d.every(200,linemove); // Button Pull-up and config pinMode(MENUBUTTON, INPUT); digitalWrite(MENUBUTTON, HIGH); pinMode(SPECIALBUTTON, INPUT); digitalWrite(SPECIALBUTTON, HIGH); mainmenu = true; menupage = 1; game1playerscore = 0; targetx = random(1,15); targetx1 = random(1,15); targetx2 = random(1,15); targetx3 = random(1,15);

GAME1OVER = true;

// Game 2

}

void loop() { if (mainmenu == true){ GAME1OVER = true; game = 0; game1playerscore = 0;

//JOYSTICK if(value3 >= 54 && value4 < 54 && value4 > 50){ Serial.println("UP"); delay(200); } else if(value3 <= 50 && value4 < 54 && value4 > 50){ Serial.println("DOWN"); delay(200); } else if(value4 <= 50 && value3 < 54 && value3 > 50 && menupage < 3){ Serial.println("RIGHT"); menupage++; delay(200); } else if(value4 >= 54 && value3 < 54 && value3 > 50 && menupage > 1){ Serial.println("LEFT"); menupage--; delay(200); } value3 = treatValue(value1); value4 = treatValue(value2);

// If user is pushing MENU button if (digitalRead(MENUBUTTON) == 0) { Serial.println("Menu"); delay(Dbutton); } // If user is pushing SPECIAL button if (digitalRead(SPECIALBUTTON) == 0) { Serial.println("Special"); if(menupage == 1){ mainmenu = false; game = 1; GAME1OVER = false; targetx = random(1,14); targety = 8; targety1 = 8; targety2 = 8; targety3 = 8; targetx1 = random(1,14); targetx2 = random(1,14); targetx3 = random(1,14); delay(150); } if(menupage == 2){ mainmenu = false; game = 2; game2score = 0; paddleX = 4; ballX = 4; ballY = 7; balldirection = random(1,4); fencecounter = 0; delay(100); } if(menupage == 3){ mainmenu = false; game = 3; } if(menupage == 4){ mainmenu = false; game = 4; } delay(Dbutton); } if(menupage == 1){ matrix.setTextSize(1); matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely matrix.setTextColor(LED_ON); matrix.setRotation(1); matrix.clear(); matrix.setCursor(0,0); matrix.print("1"); matrix.writeDisplay(); delay(10); } if(menupage == 2){ matrix.setTextSize(1); matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely matrix.setTextColor(LED_ON); matrix.setRotation(1); matrix.clear(); matrix.setCursor(0,0); matrix.print("2"); matrix.writeDisplay(); delay(10); } if(menupage == 3){ matrix.setTextSize(1); matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely matrix.setTextColor(LED_ON); matrix.setRotation(1); matrix.clear(); matrix.setCursor(0,0); matrix.print("3"); matrix.writeDisplay(); delay(10); } if(menupage == 4){ matrix.setTextSize(1); matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely matrix.setTextColor(LED_ON); matrix.setRotation(1); matrix.clear(); matrix.setCursor(0,0); matrix.print("4"); matrix.writeDisplay(); delay(10); } }// End of main menu if(game == 1){ t.update(); shoot1 = false; if(value3 >= 54 && value4 < 54 && value4 > 50){ Serial.println("UP"); shoot1 = true; delay(75); } else if(value3 <= 50 && value4 < 54 && value4 > 50){ Serial.println("DOWN"); delay(75); } else if(value4 <= 50 && value3 < 54 && value3 > 50 && gunpos < 13){ Serial.println("RIGHT"); gunpos++; delay(75); } else if(value4 >= 54 && value3 < 54 && value3 > 50 && gunpos > 0){ Serial.println("LEFT"); gunpos--; delay(75); } value3 = treatValue(value1); value4 = treatValue(value2); // If user is pushing MENU button if (digitalRead(MENUBUTTON) == 0) { Serial.println("Menu"); matrix.clear(); matrix.setRotation(1); matrix.setCursor(0,0); matrix.print(game1playerscore); matrix.writeDisplay(); delay(1000); mainmenu = true; menupage = 1; game = 0; delay(Dbutton); } // If user is pushing SPECIAL button if (digitalRead(SPECIALBUTTON) == 0) { shoot1 = true; Serial.println("Special"); delay(Dbutton); } matrix.clear(); // clear display matrix.setRotation(0); Serial.println(targety); Serial.println(targety1); matrix.drawPixel(targety, targetx, LED_ON); matrix.drawPixel(targety1, targetx1, LED_ON); if(game1playerscore >= 25){ matrix.drawPixel(targety2, targetx2, LED_ON); } if(game1playerscore >= 50){ matrix.drawPixel(targety3, targetx3, LED_ON); } matrix.drawPixel(0, gunpos, LED_ON); matrix.drawPixel(0, gunpos+1, LED_ON); matrix.drawPixel(0, gunpos+2, LED_ON); matrix.drawPixel(1, gunpos+1, LED_ON); matrix.writeDisplay(); // write the changes we just made to the display if(GAME1OVER == true){ matrix.clear(); matrix.setRotation(1); matrix.setCursor(0,0); matrix.print(game1playerscore); matrix.writeDisplay(); delay(1000); mainmenu = true; menupage = 1; game = 0; targety = 8; targety1 = 8; targety2 = 8; targety3 = 8; } if(shoot1 == true){ for(bulletpos = 1;bulletpos<9;bulletpos++){ Serial.println("SHOOT"); matrix.drawPixel(bulletpos, gunpos+1, LED_ON); matrix.writeDisplay(); // write the changes we just made to the display } if(targetx == gunpos+1 && targety > 1){ targetx = random(1,15); targety = 8; game1playerscore++; } if(targetx1 == gunpos+1 && targety1 > 1){ targetx1 = random(1,15); targety1 = 8; game1playerscore++; } if(targetx2 == gunpos+1 && game1playerscore >= 25 && targety2 > 1){ targetx2 = random(1,15); targety2 = 8; game1playerscore++; } if(targetx3 == gunpos+1 && game1playerscore >= 50 && targety3 > 1){ targetx3 = random(1,15); targety3 = 8; game1playerscore++; } } if(targety < 0 ){ GAME1OVER = true; } if(targety1 < 0 ){ GAME1OVER = true; } if(targety2 < 0 && game1playerscore >= 25){ GAME1OVER = true; } if(game1playerscore == 24){ targety2 = 9; } if(targety3 < 0 && game1playerscore >= 50){ GAME1OVER = true; } if(game1playerscore == 49){ targety3 = 9; } //die if target is hitting gun if(targety == 1 && targetx == gunpos+1 || targety1 == 1 && targetx1 == gunpos+1){ GAME1OVER = true; } if(targety == 0 && targetx == gunpos || targety == 0 && targetx == gunpos+2 || targety1 == 0 && targetx1 == gunpos || targety1 == 0 && targetx1 == gunpos+2 ){ GAME1OVER = true; } if(game1playerscore >= 25){ if(targety2 == 0 && targetx2 == gunpos || targety2 == 0 && targetx2 == gunpos+2){ GAME1OVER = true; } if(targety2 == 0 && targetx2 == gunpos || targety2 == 0 && targetx2 == gunpos+2 ){ GAME1OVER = true; } } if(game1playerscore >= 50){ if(targety3 == 0 && targetx3 == gunpos || targety3 == 0 && targetx3 == gunpos+2){ GAME1OVER = true; } if(targety3 == 0 && targetx3 == gunpos || targety3 == 0 && targetx3 == gunpos+2 ){ GAME1OVER = true; } } } if(game == 2){ // If user is pushing MENU button if (digitalRead(MENUBUTTON) == 0) { Serial.println("Menu"); mainmenu = true; game = 0; delay(Dbutton); } /* // If user is pushing RIGHT button if (digitalRead(RIGHTBUTTON) == 0 && paddleX > 0){ Serial.println("Right"); paddleX--; delay(Dbutton); } // If user is pushing LEFT button if (digitalRead(LEFTBUTTON) == 0 && paddleX < 4) { Serial.println("Left"); paddleX++; delay(Dbutton); }*/ if(value4 <= 50 && value3 < 54 && value3 > 50 && paddleX > 0){ Serial.println("RIGHT"); paddleX--; delay(75); } else if(value4 >= 54 && value3 < 54 && value3 > 50 && paddleX < 4){ Serial.println("LEFT"); paddleX++; delay(75); } // Left/Right if(ballX == 7 && balldirection == 3){ balldirection = 1; } if(ballX == 0 && balldirection == 1){ balldirection = 3; } // Up/Down if(ballY == 1 && ballup == false && ballX - paddleX >= 0 && ballX - paddleX <= 1){ // HITTING PADDLE ballup = true; balldirection = random(1,4); if(paddleX == 0){ fencecounter++; Serial.println(fencecounter); } else{ fencecounter = 0; } } if(ballY == 7 && ballup == true){ ballup = false; game2score++; } if(fencecounter == 4){ ballX = 4; ballY = 7; balldirection = random(1,4); fencecounter = 0; } matrix.setRotation(3); matrix.clear(); drawpaddle(); drawball(); drawscore2(); matrix.writeDisplay(); if(game2level == 1){ b1.update(); } else if(game2level == 2){ b2.update(); } else if(game2level == 3){ b2.update(); } else if(game2level == 4){ b3.update(); } else if(game2level == 5){ b3.update(); } else if(game2level == 6){ b4.update(); } else if(game2level == 7){ b4.update(); } else if(game2level == 8){ b4.update(); } if(ballY <= 0){ matrix.clear(); drawscore2(); matrix.writeDisplay(); delay(1000); mainmenu = true; game = 0; } } if(game == 3){ matrix.setRotation(3); d.update();

/*Serial.println(line1); Serial.println(line2); Serial.println(lineSTART);*/ Serial.println(lineHEIGHT);

// If user is pushing LEFT button if (digitalRead(SPECIALBUTTON) == 0 && paddleX < 4) { Serial.println("STOP"); if(lineHEIGHT = 1){ line1 = lineSTART; line2 = linelength; lineHEIGHT++; Serial.println("1000000"); } else if(lineHEIGHT = 2){ line3 = lineSTART; line4 = linelength; lineHEIGHT++; Serial.println("2000000"); } /*if(lineHEIGHT < 15){ lineHEIGHT++; }*/ delay(Dbutton); } matrix.clear(); if(lineHEIGHT > 1){ matrix.drawLine(1, line1, 1, line1 + line2,LED_ON); } if(lineHEIGHT > 2){ matrix.drawLine(2, line3, 2, line3 + line4,LED_ON); } //matrix.drawLine(1, 0, 1, 6,LED_ON); matrix.drawLine(0, 1, 0, 6,LED_ON); matrix.drawLine(lineHEIGHT, lineSTART, lineHEIGHT, lineSTART + linelength,LED_ON); matrix.writeDisplay(); if(lineSTART + linelength >= 7){ lineDIR = true; } else if(lineSTART <= 0){ lineDIR = false; } } if(game == 4){ // If user is pushing MENU button if (digitalRead(MENUBUTTON) == 0) { Serial.println("Menu"); mainmenu = true; game = 0; delay(Dbutton); } matrix.clear(); } value1 = analogRead(JOYUD); delay(100); value2 = analogRead(JOYLR); Serial.print(value3); Serial.println(value4); } // End of main loop

very cool! maybe a video of you playing it?

About This Instructable

1,440views

17favorites

License:

More by bobdub19:Arduino LED Matrix Handheld Gaming Console 
Add instructable to: