Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Lockup with Game Control Plus by Quark

$
0
0

I am using the GC+ library to get Windows 7 joystick movements to processing. I then use the processing program to communicate with my Arduino microprocessor. Its a great library, awesome tutorials and documentation. My problem is it works for about 5 minutes flawlessly then my processing programs totally locks up. I cannot get the program to run again unless I reboot my computer. I am sorry I cannot follow the directions for posting code. Wow what I mess I am.

 /**
 Demonstration of using a joystick for Game Control Plus

 When this sketch runs it will try and find
 a game device that matches the configuration
 file 'joystick' int the data file of the processing folder.  if it can't match this device
 then it will present you with a list of devices
 you might try and use.  Use the configurator in the Processing-->Files-->examples-->GC+ to write a data file that is included into the procesing
 folder.  You keymap and name various functions.  These are then written down below in a code. (get matched
 device and get slider).

 The chosen device requires 2 sliders and 2 buttons.
 */

import org.gamecontrolplus.gui.*;
import org.gamecontrolplus.*;
import net.java.games.input.*;

import processing.serial.*;

ControlIO control;
ControlDevice stick;
float px, py, pz, pzz;
Serial myPort;  // Create object from Serial class

public void setup() {
  myPort = new Serial(this, "COM4", 9600);//this port can be different on even the same PC.
  size(400, 400);
  // Initialise the ControlIO
  control = ControlIO.getInstance(this);
  // Find a device that matches the configuration file
  stick = control.getMatchedDevice("XBOX4"); // the device is named in the config file made by GC+ ap
  if (stick == null) {
    println("No suitable device configured");
    System.exit(-1); // End the program NOW!
  }
}

public void draw() {
  px = stick.getSlider("STEERING").getValue(); //these values are named in the config file made by  GC+ ap
  py = stick.getSlider("THROTTLE").getValue();
  pz = stick.getSlider("BRAKE").getValue();

  px=map(px,-1,1,0,255);//data from game control is usually -1.0000 to + 1.0000///PWM of Arduino requires 0-255 for analogWrite output.
  px = int(px);
  py=map(py,-1,1,127,255);
  py=int(py);
  pz=map(pz,-1,1,127,0);
  pz=int(pz);

  pzz=py-(127-pz);

delay(100);
    myPort.write("H" + int(px) + "," + int(pzz) + "\n");    //Arduino is looking for H255,255\n (can be any non numberical value to stop must be H to start)
    background(255, 255, 240);
fill(255, 0, 0);
textSize(25);
text(int(px), 75, 100);//do not write to Processing monitor it takes too long, better to write to GUI.
text(int(pzz),75,200);

}

``


Viewing all articles
Browse latest Browse all 2896

Trending Articles