GlovePie:Scripting
From WiiLi
Basic documentation on GlovePIE scripting that covers Nunchuk Support (GlovePIE .28+) for the Nintendo Wii Remote (wiimote). Adapted from included documentation along with the GlovePIE software.
Contents |
[edit] WiiRemote
GlovePIE allows you to script for Wii remotes, the following is an overview on how to get started.
[edit] Button Press
You are able to set each button (excluding the power button, as of GlovePIE .28 and below) to correspond to a keyboard button. To do this you simply assign the variable with a keyboard button.
Example:
keyboard.b = wiimote.A or down = wiimote.A
You can also assign the buttons to execute certain wiimote functions such as the rumble feature.
Example:
if wiimote.A wiimote.rumble = 1 wait 100ms wiimote.rumble = 0 endif
or (without if):
wiimote.rumble = wiimote.A wait 100ms wiimote.rumble = 0
[edit] Force/Raw Force
New: gx, gy, gz Old: RawForceX, RawForceY, and RawForceZ
They use the standard left-handed coordinate system used by everything in GlovePIE, not the Wiimote coordinate system.
Note that a stationary Wiimote has a force of 1 G holding it up, otherwise it would be falling due to gravity’s 1 G force. The other forces should be 0 on a stationary Wiimote.
Note that RawForceX, RawForceY and RawForceZ are in unknown units, and they are offset slightly due to manufacturing differences in the Wiimote hardware. Your GlovePIE script will need to take this into account.
Example:
// Dpad facing you
if wiimote.gz <= -0.45
say("Tilt Left")
wait 250 ms
endif
[edit] Acceleration/Raw Acceleration
New: RelAcc (all 3 axis), RelAccX, RelAccY, RelAccZ Old: RawAcc (all 3 axis), RawAccX, RawAccY, RawAccZ
These variables provide values for acceleration on three different axis, in m/s/s. Suffix in coding is m per s per s. ie: -10 m per s per s, when testing for conditions.
Example:
if RelAccX <= -10 m per s per s
Say("Hello World")
endif
[edit] Roll/Pitch
The roll/pitch outputs the amount (in degrees) of roll/pitch rotation in the Wii Remote. The Wiimote doesn’t contain gyros, so it has no way of determining the yaw rotation without using an imitation sensor bar. But it can sort-of tell which way is down, based on the force of gravity. This allows it to measure pitch and roll rotations.
Example:
if wiimote.roll > 50 degrees
Say("Hello There Sexy")
endif
[edit] Battery
Outputs the amount of (int) battery life left, from 0 to 192.
Example:
// Full battery outputs 100, Dead battery outputs 0
var.1 = wiimote.Battery /192 *100
debug = var.1 and("%")
[edit] LED Lights
See also GlovePIE → LEDs
Allows you to toggle the LED lights found at the bottom of the Wiimote. Used to display the player number.
Leds: Defines "all" four lights, can be set from 0-15.
Led1,Led2,Led3,Led4: Defines individual lights, can be set to a boolean value or 0 (off) or 1 (on).
The LEDs are read from left to right in a binary fashion, so if Leds = 7, then the result would be:
[♦][♦][♦][ ]
Example:
wiimote.Leds = 0 if wiimote.Count = 4 wiimote4.Leds = 1 endif if wiimote.Count = 3 wiimote3.Leds = 2 endif if wiimote.Count = 2 wiimote2.Leds = 4 endif if wiimote.Count = 1 wiimote1.Leds = 8 endif
Result:
Wii mote 1: [♦][ ][ ][ ]
Wii mote 2 (if available): [ ][♦][ ][ ]
Wii mote 3 (if available): [ ][ ][♦][ ]
Wii mote 4 (if available): [ ][ ][ ][♦]
[edit] Sensor Bar
This new version in theory supports the pointer function of the Wiimote Sensor Bar. The sensor bar is just a bunch of Infra Red lights which are always on. You can make your own fake sensor bar with candles, Christmas tree lights, or Infra-Red remote controls with a button held down.
You can read the position of the infra-red dots that the Wiimote can see with:
wiimote.dot1x, wiimote.dot1y … wiimote.dot4x, wiimote.dot4y
= You can tell whether an infra-red dot can be seen with Wiimote.dot1vis to Wiimote.dot4vis = You can tell the size of a dot (between 0 and 15) with Wiimote.dot1size to Wiimote.dot4size
[edit] Extension Port (nunchuk/classic)
GlovePIE can tell when they are plugged in like this:
Wiimote.HasNunChuck Wiimote.HasClassic
Example:
if Wiimote.HasNunChuck Keyboard.A = wiimote.nunchuck.cbutton endif
[edit] Multiple Wiimote Scripting
You can tell how many Wiimotes there are with Wiimote.Count
You can access a particular wiimote by putting a number after the word “wiimote” and before the dot. For example:
Enter = wiimote2.A
[edit] Nunchuk
[edit] Force/Raw Force
[edit] Acceleration/Raw Acceleration
[edit] Roll/Pitch
Can be accessed through the Nunchuk.gx / gy / gz values.
Example:
var.nzRot = Wiimote.Nunchuk.gz if var.nzRot >= 0.8 then // Do something when tilting the Nunchuk back towards you end if if var.nzRot <= -0.6 then // Do something when tilting the Nunchuk down away from you end if
[edit] Analog
The Nunchuk contains an analog joystick, similar to the ones found on the other console controllers. They are accessed through the Wiimote.Nunchuk section.
Example:
A = (-1.2 < wiimote.Nunchuk.JoyX < -0.5) // Joystick moving Left = minus X axis D = (0.5 < wiimote.Nunchuk.JoyX < 1.2) // Joystick moving Right = positive X axis W = (-1.2 < wiimote.Nunchuk.JoyY < -0.5) // Joystick moving Up = negative Y axis S = (0.5 < wiimote.Nunchuk.JoyY < 1.2) // Joystick moving Down = positive Y axis
or:
Mouse.WheelUp = (-1.2 < wiimote.Nunchuk.JoyY < -0.5) Mouse.WheelDown = (0.5 < wiimote.Nunchuk.JoyY < 1.2)


