controls()
Purpose
Read all values from the Joy-Con controllers
Description
Used to establish the state of buttons, position of control sticks and motion sensors. It is advisable not to read the value of this function directly but to assign to to a variable first.
Syntax
c = controls( index )
Arguments
index Index of the controller (0 to 3)
c.a State of the A button (0 or 1)
c.b State of the B button (0 or 1)
c.x State of the X button (0 or 1)
c.y State of the Y button (0 or 1)
c.up State of the up (\^) button (0 or 1)
c.down State of the down (v) button (0 or 1)
c.left State of the left (<) button (0 or 1)
c.right State of the right (>) button (0 or 1)
c.l State of the L button (0 or 1)
c.r State of the R button (0 or 1)
c.zl State of the ZL button (0 or 1)
c.zr State of the ZR button (0 or 1)
c.lx Horizontal position of the left control stick (-1 to 1)
c.ly Vertical position of the left control stick (-1 to 1)
c.rx Horizontal position of the right control stick (-1 to 1)
c.ry Vertical position of the right control stick (-1 to 1)
c.lc State of the left stick press (0 or 1)
c.rc State of the right stick press (0 or 1)
c.velocity[0] Velocity of the left controller (or both if connected) \{ x, y, z \}
c.velocity[1] Velocity of the right controller (if disconnected) \{ x, y, z \}
c.orientation[0] Orientation of the left controller (or both if connected) \{ x, y, z \}
c.orientation[1] Orientation of the right controller (if disconnected) \{ x, y, z \}
Example
loop
clear()
c = controls( 0 )
printAt( 0, 0, "zl: ", c.zl )
printAt( 0, 1, "l: ", c.l )
printAt( 0, 3, "lx: ", c.lx )
printAt( 0, 4, "ly: ", c.ly )
printAt( 35, 0, "zr: ", c.zr )
printAt( 35, 1, "r: ", c.r )
printAt( 38, 4, "A: ", c.a )
printAt( 35, 5, "B: ", c.b )
printAt( 35, 3, "X: ", c.x )
printAt( 32, 4, "Y: ", c.y )
printAt( 3, 11, "^: ", c.up )
printAt( 3, 13, "v: ", c.down )
printAt( 0, 12, "<: ", c.left )
printAt( 6, 12, "> ", c.right )
printAt( 33, 11, "rx: ", c.rx )
printAt( 33, 12, "ry: ", c.ry )
printAt( 0, 6, "lc: ", c.lc )
printAt( 33, 14, "rc: ", c.rc )
printAt( 0, 18, "velocity (l): ", c.velocity[0] )
printAt( 0, 19, "velocity (r): ", c.velocity[1] )
printAt( 0, 20, "orientation (l): ", c.orientation[0] )
printAt( 0, 21, "orientation (r): ", c.orientation[1] )
update()
repeat
Associated Commands
input(), docked(), getKeyboardBuffer(), showKeyboard(), touch(), hideKeyboard()