-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
Vincent Ferrara edited this page Jul 24, 2017
·
3 revisions
Once everything has been installed, you are free to use the library in any way imaginable.
At the beginning of the program, initialize the controller object by calling
GC_Controller NAME(PIN_NUMBER,BOARD_TYPE);
(See Board Compatibility). The pin does not have to be setup in any way, as the library will handle that. NAME can be any variable name, which will be gc for the rest of this page.
The GC_Controller object has three public member functions that will change the state of the controller.
-
gc.update()will attempt to read the controller and update the member variables. Although it doesn't have to be, this function should be called inside a timer interrupt. The timer can be set to any rate that will work for your application, but 30ms is a good start. -
gc.set_j_deadzone(CONST UINT DEADZONE)changes the deadzone for the gray joystick to the number passed in, up to 120. This means that if the analog value of the joystick is within that amount from center, the joystick will be kept at center. This will prevent jittering when the stick is in the neutral position. The deadzone is 0 by default. -
gc.set_c_deadzone(CONST UINT DEADZONE)changes the deadzone for the c-stick to the number passed in, up to 120.
There are several member functions that return information about the state of the controller.
-
gc.is_connected()returnstrueif the controller was connected the last time it was updated. This can be determined by checking if all of the bits that were read were 1, which should be impossible if the controller is connected. -
gc.raw_datareturns a 64-bitunsigned long longcontaining all the the data read by the Arduino. This does not account for the deadzones. -
gc.A()returnstrueif the A button was pressed. -
gc.B()returnstrueif the B button was pressed. -
gc.X()returnstrueif the X button was pressed. -
gc.Y()returnstrueif the Y button was pressed. -
gc.L()returnstrueif the L button was pressed. -
gc.R()returnstrueif the R button was pressed. -
gc.Z()returnstrueif the Z button was pressed. -
gc.START()returnstrueif the Start button was pressed. -
gc.D_UP()returnstrueif the up button on the d-pad was pressed. -
gc.D_DOWN()returnstrueif the down button on the d-pad was pressed. -
gc.D_LEFT()returnstrueif the left button on the d-pad was pressed. -
gc.D_RIGHT()returnstrueif the right button on the d-pad was pressed. -
gc.JOY_X()returns an 8-bitunsigned charof the x-position of the gray joystick. -
gc.JOY_Y()returns an 8-bitunsigned charof the y-position of the gray joystick. -
gc.C_X()returns an 8-bitunsigned charof the x-position of the c-stick. -
gc.C_Y()returns an 8-bitunsigned charof the y-position of the c-stick. -
gc.L_TRIGGER()returns an 8-bitunsigned charof the position of the left trigger. -
gc.R_TRIGGER()returns an 8-bitunsigned charof the position of the right trigger.
The further the trigger is pressed, the higher the value.
With gc.update() placed in a timer interrupt, the following code will toggle an LED after the A button is pressed twice:
void loop() {
while (gc.is_connected()) {
while (!gc.A()); //Wait for first press
while (gc.A()); //Wait for release
while (!gc.A()); //Wait for second press
//Toggle LED
while (gc.A()); //Wait for release
}
}