Go Down

Topic: Funduino Joystick Shield to communicate with PC ? (Read 175 times) previous topic - next topic

Ryan_Williams

Jan 26, 2016, 02:08 pm Last Edit: Jan 26, 2016, 02:16 pm by Ryan_Williams
Okay so I posted into the forums about a week ago, on a slightly different topic about the feasibility of my project, which can be found here.

But I've received the parts from ebay and I have code set up onto the shield, but I'm oblivious as to how I go from outputs on a serial monitor, to work on a PC. This is what I am working with:



Code: [Select]

#include <JoystickShield.h> // include JoystickShield Library

JoystickShield joystickShield; // create an instance of JoystickShield object

void setup() {
    Serial.begin(9600);
  
    delay(100);
    // new calibration function
    joystickShield.calibrateJoystick();
    
 // predefined Joystick to Pins 0 and 1.
 // Change it if you are using a different shield
 // setJoystickPins(0, 1);
  
 // predefined buttons to the following pins.
 // change it if you are using a different shield.
 // setButtonPins(pinJoystickButton, pinUp, pinRight, pinDown, pinLeft, pinF, pinE);
 // to deactivate a button use a pin outside of the range of the arduino e.g. 255, but not above
 // setButtonPins(8, 2, 3, 4, 5, 7, 6);
}

void loop() {
  joystickShield.processEvents(); // process events

  if (joystickShield.isUp()) {
     Serial.println("Up") ;
  }

  if (joystickShield.isRightUp()) {
     Serial.println("RightUp") ;
  }

  if (joystickShield.isRight()) {
     Serial.println("Right") ;
  }

  if (joystickShield.isRightDown()) {
     Serial.println("RightDown") ;
  }

  if (joystickShield.isDown()) {
     Serial.println("Down") ;
  }

  if (joystickShield.isLeftDown()) {
     Serial.println("LeftDown") ;
  }

  if (joystickShield.isLeft()) {
     Serial.println("Left") ;
  }

  if (joystickShield.isLeftUp()) {
     Serial.println("LeftUp") ;
  }

  if (joystickShield.isJoystickButton()) {
     Serial.println("Joystick Clicked") ;
  }

  if (joystickShield.isUpButton()) {
     Serial.println("A Button Clicked") ;
  }

  if (joystickShield.isRightButton()) {
     Serial.println("B Button Clicked") ;
  }

  if (joystickShield.isDownButton()) {
     Serial.println("C Button Clicked") ;
  }

  if (joystickShield.isLeftButton()) {
     Serial.println("D Button Clicked") ;
  }

  // new eventfunctions
  if (joystickShield.isFButton()) {
     Serial.println("E Button Clicked") ;
  }

  if (joystickShield.isEButton()) {
     Serial.println("F Button Clicked") ;
  }  

  
  // new position functions
  // Serial.print("x "); Serial.print(joystickShield.xAmplitude());Serial.print(" y ");Serial.println(joystickShield.yAmplitude());

  delay(500);
}


The code was slightly adjusted to simplify the output on the serial monitor. I've looked online and in the forums here to find an example of someone using the joystick shield to work on their computer. For demonstration reasons I need to develop this so it works on the computer, and the best way to do so is to configure it as a controller that can play a simple game, such as an emulated SNES or PS1 game? Does anyone have any info or suggestions as what to do?

Is there an external programme or certain code needed so this can run as a game controller and run an application ?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy