How to control LED matrix using a joystick with Arduino



Materials:-

  • Arduino uno
  • joystick
  • LED matrix 4*4
Diagram:-

Connections:-

  • Joystick Vcc = Arduino 5V   
  • Joystick GND = Arduino GND
  • Joystick URX = Arduino analog pin 5
  • joystick URY = Arduino analog pin 4       
  • LED matrix Vcc = Arduino 3.5V
  • LED matrix GND = Arduino GND
  • LED matrix DIN = Arduino Digital pin 13
  • LED matrix CS = Arduino Digital pin 12
  • LED matrix CLK = Arduino Digital pin 11
Code :-

int UY = 0;
int UX = 0; 
#include "LedControl.h" //  library
LedControl lc=LedControl(13,11,12,1); //11 is to CLOCK, 12 = CS, 13=DIN//


void setup() {
  Serial.begin(9600);

  lc.shutdown(0,false);
  lc.setIntensity(0,8);// sets brightness 
  lc.clearDisplay(0);// clear screen

}

void loop() {
  UY = analogRead(A5);
  UX = analogRead(A4);
  char x_translate = map(UX, 1021, 0, 7, 0); 
  char y_translate = map(UY, 1021, 0, 0, 7);
  
  Serial.print(", LR = ");
  Serial.print(UX, DEC);
   Serial.print("UD = ");
  Serial.print(UY, DEC);
  Serial.print(", x = ");
  Serial.println(y_translate, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC); 
  Serial.print(", y = ");
    lc.clearDisplay(0);
    lc.setLed(0,x_translate,y_translate,true);  
  delay(150); 
}