FrenchMasterSword
Published © MIT

Draw with LEDs and Logic

Easily draw whatever you want on an LED matrix with just a joystick.

BeginnerFull instructions provided3 minutes1,841

Things used in this project

Hardware components

Elecrow MAX7219 8x8 Matrix Display Module - Red Dot
×1
Elecrow Thumb joystick module
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Assembly

Please note that the LED matrix only have 5 pins, and that HORZ and VERT refer to Vr_x and Vr_y on the joystick

Code

Paint_source_code

Arduino
/* https://www.hackster.io/projects/6248f2
 * Created by FrenchMasterSword
 * 2017.12.27
 * 
 * Allows to draw and erase linearly
 * on a MAX7219 LED matrix
 * 
 * Pin layout: component - UNO
 * ----Joystick - UNO----
 * SW - 2
 * Vry - A0
 * Vrx - A1
 * +5V - 5V
 * GND - GND
 * ----MAX7219 - UNO---
 * VCC - 5V
 * GND - GND
 * DIN - 12
 * CS - 11
 * CLK - 10
 */

#include "LedControl.h" // library to control matrix

LedControl lc=LedControl(12,10,11,1); // initialise matrix

bool writing = false;

const int SW_pin = 2; // digital pin for 'select' output
const int X_pin = 1; // analog pin for X output
const int Y_pin = 0; // analog pin for Y output

/*proportions of the matrix (from 0 to 7)*/
const int matrixSizeX = 7;
const int matrixSizeY = 7;

int abscissa = 0;
int ordinate = 0;

unsigned int delayTime1 = 500;
unsigned int delayTime2 = delayTime1/2;

void setup() {
  lc.shutdown(0, false); // wakeup call
  lc.setIntensity(0,8);
  lc.clearDisplay(0);

  pinMode(SW_pin, INPUT); // 'select' pin
  digitalWrite(SW_pin, HIGH); // 'select' is on
}

void loop() {
  /*Light the LED in writing mode*/
  if (writing){
    lc.setLed(0,abscissa,ordinate,true);
  }
  /*The joystick returns a value between 0 and 1024
  so 256 and 768 corresponds to a half leaned joystick in respective directions*/
  
  /*The way we hold the joystick is mirrored so the values mean the opposite*/
  if ((analogRead(X_pin) > 767)&&(abscissa > 0)){
    abscissa--;
  }
  if ((analogRead(X_pin) < 257)&&(abscissa < matrixSizeX)){
    abscissa++;
  }
  if ((analogRead(Y_pin) > 767)&&(ordinate < matrixSizeY)){
    ordinate++;
  }
  if ((analogRead(Y_pin) < 257)&&(ordinate > 0)){
    ordinate--;
  }

  /*The 'select' returs 1 when up ; and 0 when down*/
  if (digitalRead(SW_pin)==0){
    /*We alternate the value of writing*/
    if (writing){
      writing=false;
    }
    else{
      writing=true;
    }

    /*We signal the modification by a quicker blink*/
    lc.setLed(0,abscissa,ordinate,true);
    delay(delayTime2);  
    lc.setLed(0,abscissa,ordinate,false);
    delay(delayTime2);
  }

  /*Blinking point*/
  lc.setLed(0,abscissa,ordinate,true);
  delay(delayTime1);  
  lc.setLed(0,abscissa,ordinate,false);
  delay(delayTime1);
}

Credits

FrenchMasterSword
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.