Last active
November 22, 2016 23:14
-
-
Save slambert/a79573d6b51bfc078a5600be824640c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Game Controller Example | |
// Steve Lambert around November 24, 2015 | |
// import libraries | |
import net.java.games.input.*; | |
import org.gamecontrolplus.*; | |
import org.gamecontrolplus.gui.*; | |
ControlIO control; | |
Configuration config; | |
ControlDevice gpad; | |
void setup() { | |
size(640, 640); | |
background(255); | |
// game controller stuff | |
control = ControlIO.getInstance(this); | |
gpad = control.getMatchedDevice("sabrent"); // <-- insert name of your controller/config file? | |
// read your config file to find the names you gave your buttons and joysticks!! | |
if (gpad == null) { | |
println("No suitable device configured"); | |
System.exit(-1); // End the program NOW! | |
} | |
} // setup | |
void draw() { | |
boolean b1 = gpad.getButton("buttonL1").pressed(); // <-- buttonL1 is the keyname I gave | |
float stickLx = gpad.getSlider("LeftStickX").getValue(); // -1 to 1 <-- leftStickX is the name I gave | |
float stickLy = gpad.getSlider("LeftStickY").getValue(); // -1 to 1 <-- leftStickY is the name I gave | |
float stickLx_ = map(stickLx,-1,1,0,width); // mapped 0 to width | |
float stickLy_ = map(stickLy,-1,1,0,height); // mapped 0 to width | |
if (b1 == true){ | |
background(255, 0, 0); // red! | |
} | |
if (b1 == false){ | |
background(0); | |
} | |
noStroke(); | |
fill(255, 125); | |
ellipse(stickLx_,stickLy_,30,30); | |
} // draw | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment