newproyecto
Published © GPL3+

Joystick con lcd joystick with lcd

Tells you what you do with the joystick te dice lo que haces con el joystick

IntermediateFull instructions provided3,004
Joystick con lcd joystick with lcd

Things used in this project

Hardware components

Analog joystick (Generic)
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
5 mm LED: Red
5 mm LED: Red
×2
LED, Blue Green
LED, Blue Green
×2
Resistor 221 ohm
Resistor 221 ohm
×4
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

untitled_sketch_bb_SBiZ4aInYi.png

Code

Untitled file

Arduino
#include <Wire.h>                 
#include <LiquidCrystal_I2C.h>    

LiquidCrystal_I2C lcd(0x27,16,2); 
                                  
#define joyX A0
#define joyY A1

int button=2;
int buttonState = 0;
int buttonState1 = 0;

void setup() {
  pinMode(7,OUTPUT);
  pinMode(button,INPUT);
  digitalWrite(button, HIGH);
  lcd.init();                     
  lcd.backlight(); 
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
}
 
void loop() {

 int xValue = analogRead(joyX);
 int yValue = analogRead(joyY);
  
  buttonState = digitalRead(button);
  if (xValue>=0 && yValue<=10)
  {
  digitalWrite(10, HIGH);
  lcd.setCursor(0,0);
  lcd.print("left ");
  }
  else{digitalWrite(10, LOW);}

  if (xValue<=10 && yValue>=500)
  {
    digitalWrite(11, HIGH);
     lcd.setCursor(0,0);
     lcd.print("down ");
  }
  else{digitalWrite(11, LOW);}

  if (xValue>=1020 && yValue>=500)
  {
    digitalWrite(9, HIGH);
    lcd.setCursor(0,0);
   lcd.print("up   ");
  }
  else{digitalWrite(9, LOW);}
  
  if (xValue>=500 && yValue>=1020)
  {
    digitalWrite(8, HIGH);
    lcd.setCursor(0,0);
    lcd.print("right");
  }
  else{digitalWrite(8, LOW);}

  if (xValue>=1020 && yValue>=1020)
  {
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
  }
}

Credits

newproyecto

newproyecto

3 projects • 4 followers
Hello everyone, my name is Antonio and I love programming and doing projects with Arduino and I hope these projects will help you.

Comments