DrOpShOtZ
Published

Arduino Thumb Joystick to Processing

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

BeginnerProtip20,912
Arduino Thumb Joystick to Processing

Things used in this project

Story

Read more

Schematics

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

The circuit diagram

Code

Arduino Code

Arduino
int xValue = 0 ;
int yValue = 0 ; 
int bValue = 0 ;

void setup()	
{	
	Serial.begin(9600) ;
	pinMode(8,INPUT); 
	digitalWrite(8,HIGH);	
}	

void loop()	
{	
	xValue = analogRead(A0);	
	yValue = analogRead(A1);	
	bValue = digitalRead(8);	
	Serial.print(xValue,DEC);
	Serial.print(",");
	Serial.print(yValue,DEC);
	Serial.print(",");
	Serial.print(!bValue);
	Serial.print("\n");
	delay(10);	
}

Processing Code

Processing
import processing.serial.*;
Serial myPort;

int x; 
int y;
int b;
PFont f;
String portName;
String val;

void setup()
{
  size ( 512 , 512 ) ; 
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n'); 
  f = createFont("Arial", 16, true);
  textFont ( f, 16 ) ; 
}


void draw()
{
  fill(0) ;
  clear() ; 
  fill(255) ; 
  if (b == 1)
  {
    ellipse(x/2,y/2, 50, 50);
  } 
  else
  {
    ellipse(x/2,y/2, 25, 25);
  }
  text("AnalogX="+(1023-x)+" AnalogY="+(1023-y),10,20);
}


void serialEvent( Serial myPort) 
{
  val = myPort.readStringUntil('\n');
  if (val != null)
  {
        val = trim(val);
    int[] vals = int(splitTokens(val, ","));
    x = vals[0];
    y = vals[1] ;
    b = vals[2];

  }

Credits

DrOpShOtZ

DrOpShOtZ

12 projects • 17 followers
Contact me from Discord. DrOpShOtZ#6290

Comments