Devices & Components
Arduino Uno Rev3
Analog joystick (Generic)
Breadboard (generic)
Jumper wires (generic)
LED (generic)
USB-A to B Cable
Project description
Code
The code
arduino
This is the code that you will paste into your editor in order to make this project work.
1#define joyX A0 2#define joyY A1 3 4int button=2; 5int buttonState = 0; 6int buttonState1 = 0; 7 8void setup() { 9 pinMode(7,OUTPUT); 10 pinMode(button,INPUT); 11 digitalWrite(button, HIGH); 12 Serial.begin(9600); 13 14 pinMode(8,OUTPUT); 15 pinMode(9,OUTPUT); 16 pinMode(10,OUTPUT); 17 pinMode(11,OUTPUT); 18} 19 20void loop() { 21 22 int xValue = analogRead(joyX); 23 int yValue = analogRead(joyY); 24 Serial.print(xValue); 25 Serial.print("\ "); 26 Serial.println(yValue); 27 28 buttonState = digitalRead(button); 29 Serial.println(buttonState); 30 if (xValue>=0 && yValue<=10) 31 { 32 digitalWrite(10, HIGH); 33 } 34 else{digitalWrite(10, LOW);} 35 36 if (xValue<=10 && yValue>=500) 37 { 38 digitalWrite(11, HIGH); 39 } 40 else{digitalWrite(11, LOW);} 41 42 if (xValue>=1020 && yValue>=500) 43 { 44 digitalWrite(9, HIGH); 45 } 46 else{digitalWrite(9, LOW);} 47 48 if (xValue>=500 && yValue>=1020) 49 { 50 digitalWrite(8, HIGH); 51 } 52 else{digitalWrite(8, LOW);} 53 54 if (xValue>=1020 && yValue>=1020) 55 { 56 digitalWrite(9, LOW); 57 digitalWrite(8, LOW); 58 } 59 60 if (buttonState == LOW) 61 { 62 Serial.println("Switch = High"); 63 digitalWrite(7, HIGH); 64 } 65 else{digitalWrite(7, LOW);} 66 buttonState1 = digitalRead(7); 67 Serial.println(buttonState1); 68 delay(100); 69} 70
Downloadable files
The schematic
This will help you to connect all your components together as the wiring in my image was a mess.
The schematic

The schematic
This will help you to connect all your components together as the wiring in my image was a mess.
The schematic

Comments
Only logged in users can leave comments