Published

Simple Joystick with LED

A simple joystick project controlling LEDs.

BeginnerShowcase (no instructions)4,887
Simple Joystick with LED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun Thumb Joystick Breakout
SparkFun Thumb Joystick Breakout
×1
Jumper wires (generic)
Jumper wires (generic)
×30
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×4
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Diagram For Joystick

It is a diagram for the thumb joystick, this does not include the led's

Code

Arduino Thumb Joystick

C/C++
The code file for the whole project
int UD = 0;
int LR = 0;
int DWN = 13;
int UP = 12;
int LEFT = 11;
int RT = 10;
int IUP=A0;
int ILR=A1;
int MID = 10;
int LRMID = 0;
int UPMID = 0;

void setup(){

pinMode(DWN, OUTPUT);
pinMode(UP, OUTPUT);
pinMode(LEFT, OUTPUT);
pinMode(RT, OUTPUT);
digitalWrite(DWN, HIGH);
digitalWrite(UP, HIGH);
digitalWrite(LEFT, HIGH);
digitalWrite(RT, HIGH);
LRMID = analogRead(ILR);
UPMID = analogRead(IUP); }

void loop(){

UD = analogRead(IUP);
LR = analogRead(ILR);

if(UD < UPMID - MID){
digitalWrite(DWN, HIGH);
}else{
digitalWrite(DWN, LOW);
}

if(UD > UPMID + MID)
{ digitalWrite(UP, HIGH);
}else{
digitalWrite(UP, LOW);
}

if(LR < LRMID - MID){
digitalWrite(LEFT, HIGH);
}else{
digitalWrite(LEFT, LOW);
}

if(LR > LRMID + MID){
digitalWrite(RT, HIGH);
}else{
digitalWrite(RT, LOW);
}
delay(400);
}

Credits

Comments