gregoriomasetta
Published © GPL3+

Dot Matrix Drawing

Use the Joystick to move a dot on the MAX7219 LED Dot Matrix

IntermediateFull instructions provided917
Dot Matrix Drawing

Things used in this project

Hardware components

Analog joystick (Generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×10
Male/Male Jumper Wires
×16
Arduino UNO
Arduino UNO
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

MAX7219_joystick.ino

Arduino
//We always have to include the library
#include "LedControl.h"
#include <LiquidCrystal.h>
/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to LOAD(CS)
 pin 10 is connected to the CLK 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(4,5,6,1);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

/* we always wait a bit between updates of the display */
unsigned long delaytime1=500;
unsigned long delaytime2=50;

boolean pixels[8][8];
         

const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output


int row = 4;
int column = 4;
boolean cursorFlickerStatus = true;


void setup() {

    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,0);
  /* and clear the display */
  lc.clearDisplay(0);

  /* setup joystic */
   pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600); 

  for(int i=0; i < 8; i++)
    for(int l=0; l < 8; l++)
    {
      pixels [i][l] = false;
    }
}


void updateLED()
{
  lc.setLed(0,column,row,cursorFlickerStatus);  

  for(int i=0; i < 8; i++)
    for(int l=0; l < 8; l++)
    {
      lc.setLed(0,l,i,pixels[i][l]); 
    }
}

void loop() 
{ 

  lcd.setCursor(0, 1);

  String output = "";
  output+= "x:";
  output+= column;
  output+= "  y:";
  output+= row;

  lcd.print(output);
  

  cursorFlickerStatus = !cursorFlickerStatus;

    
  if(digitalRead(SW_pin) == 0)
  {
   
    pixels[row][column] = !pixels[row][column];
    updateLED();
    delay(1000);
  }


  if(analogRead(X_pin) < 512 -100 )
  {

    lc.setLed(0,column,row,false);  
    
    row = row -1;
    if(row < 0)
      row = 0; 
    
    updateLED();
    delay(100);
  }
  else if(analogRead(X_pin) > 512 +100 )
  {
    lc.setLed(0,column,row,false);  
    
    row = row +1;
    if(row > 7)
      row = 7; 
        
    updateLED();
    delay(100);
  }

   if(analogRead(Y_pin) < 512 -100 )
  {

    lc.setLed(0,column,row,false);  
    
    column = column -1;
    if(column < 0)
      column = 0; 
    
    updateLED();
    delay(100);
  }
  else if(analogRead(Y_pin) > 512 +100 )
  {
    lc.setLed(0,column,row,false);  
    
    column = column +1;
    if(column > 7)
      column = 7; 
        
    updateLED();
    delay(100);
  }
  
  updateLED();

}

Credits

gregoriomasetta
3 projects • 0 followers

Comments