Devices & Components
Arduino Uno Rev3
Thumb Joystick
Jumper wires (generic)
Software & Tools
Processing
Arduino IDE
Project description
Code
Arduino Code
arduino
1int xValue = 0 ; 2int yValue = 0 ; 3int bValue = 0 ; 4 5void setup() 6{ 7 Serial.begin(9600) ; 8 pinMode(8,INPUT); 9 digitalWrite(8,HIGH); 10} 11 12void loop() 13{ 14 xValue = analogRead(A0); 15 yValue = analogRead(A1); 16 bValue = digitalRead(8); 17 Serial.print(xValue,DEC); 18 Serial.print(","); 19 Serial.print(yValue,DEC); 20 Serial.print(","); 21 Serial.print(!bValue); 22 Serial.print("\ 23"); 24 delay(10); 25}
Processing Code
processing
1import processing.serial.*; 2Serial myPort; 3 4int x; 5int y; 6int b; 7PFont f; 8String portName; 9String val; 10 11void setup() 12{ 13 size ( 512 , 512 ) ; 14 myPort = new Serial(this, Serial.list()[0], 9600); 15 myPort.bufferUntil('\n'); 16 f = createFont("Arial", 16, true); 17 textFont ( f, 16 ) ; 18} 19 20 21void draw() 22{ 23 fill(0) ; 24 clear() ; 25 fill(255) ; 26 if (b == 1) 27 { 28 ellipse(x/2,y/2, 50, 50); 29 } 30 else 31 { 32 ellipse(x/2,y/2, 25, 25); 33 } 34 text("AnalogX="+(1023-x)+" AnalogY="+(1023-y),10,20); 35} 36 37 38void serialEvent( Serial myPort) 39{ 40 val = myPort.readStringUntil('\n'); 41 if (val != null) 42 { 43 val = trim(val); 44 int[] vals = int(splitTokens(val, ",")); 45 x = vals[0]; 46 y = vals[1] ; 47 b = vals[2]; 48 49 } 50
Arduino Code
arduino
1int xValue = 0 ; 2int yValue = 0 ; 3int bValue = 0 ; 4 5void 6 setup() 7{ 8 Serial.begin(9600) ; 9 pinMode(8,INPUT); 10 digitalWrite(8,HIGH); 11} 12 13void 14 loop() 15{ 16 xValue = analogRead(A0); 17 yValue = analogRead(A1); 18 bValue 19 = digitalRead(8); 20 Serial.print(xValue,DEC); 21 Serial.print(","); 22 Serial.print(yValue,DEC); 23 Serial.print(","); 24 Serial.print(!bValue); 25 Serial.print("\ 26"); 27 delay(10); 28}
Downloadable files
How 2-Axis Joystick Works & Interface with Arduino + Processing
The circuit diagram
How 2-Axis Joystick Works & Interface with Arduino + Processing

How 2-Axis Joystick Works & Interface with Arduino + Processing
The circuit diagram
How 2-Axis Joystick Works & Interface with Arduino + Processing

Comments
Only logged in users can leave comments