promo
GlovePie Tutorial 3

GlovePie Tutorial Section 3


In this part, you'll see what variables do within GlovePIE, how they function and hopefully we'll even get to flickstarting and how that functions in both the script on the site and also in my script I made for myself.

So variables are things that you can assign values to. It's really quite simple accutally, for example a line of code like

a = Wiimote1.A


Sets the A button on the wiimote equal to the letter A. So paste that line of code into GlovePIE, run GlovePIE (obviously) and then open up notepad. Try pressing the A button on the Wiimote and you'll soon see the letter A being typed in notepad. I've not heard of anyone making a keyboard script for GlovePIE yet...but one can only think of replacing the existing Keyboard with two Wiimotes...it could be our future :).

So assigning values to a variable are that easy. So what are all the different variables for the Wiimote? Well I'm glad you asked. The lowercase n in the list below is whatever you are assigning the variable to (like the letter you are assigning the A button to be the letter a)

Uppercase N is the number of Wiimote you are trying to send information to or get it from. If you only have one, you can simply give commands by Wiimote.A, but if you have more then one, then it's Wiimote1.A.

 ·A – n=WiimoteN.A
·B – n=WiimoteN.B
·Up – n=WiimoteN.Up
·Down – n=WiimoteN.Down
·Left – n=WiimoteN.Left
·Right – n=WiimoteN.Right
·Minus – n=WiimoteN.Minus
·Plus – n=WiimoteN.Plus
·Home – n=WiimoteN.Home
·One – n=WiimoteN.One
·Two – n=WiimoteN.Two


So to see a good example of this, download any of the GlovePIE scripts from this site and you will see a section right at the top where you have two Wiimotes both assigned with variables that look something like this. (You have to go past all of the stuff that's purple. All that is, is commented out information so anyone can put in what's going on in the code without the program thinking it's programing language, for example //wiimote.One is that)

 //wiimote.One

c = Wiimote1.A
b = Wiimote1.Home
r = Wiimote1.Right
t = Wiimote1.Left
u = Wiimote1.Up
i = Wiimote1.Down
n= Wiimote1.Plus
m = Wiimote1.Minus
a = Wiimote1.One
s = Wiimote1.Two
//wiimote.Two

p = Wiimote2.A
l = Wiimote2.B
o = Wiimote2.Home
k = Wiimote2.Right
z = Wiimote2.Left
j = Wiimote2.Up
f = Wiimote2.Down
h= Wiimote2.Plus
d = Wiimote2.Minus
q = Wiimote2.One
w = Wiimote2.Two

So these lists show how each of the buttons on the two Wiimotes used for Wiijing get assigned. However, there is one other thing you can assign values to, and those are the little LED lights on the bottom of the Wiimote. If you've been running any of the code I've given you thusfar, you'll ntoice that there was no way of telling if you were using Wiimote 1 or 2 becuase there were no LED lights on the bottom telling you. Well here is how you assign that.

·Led – WiimoteN.LedN = TRUE
Led values. From 1 to 4, left to right respectively on the Wiimote. To turn on an LED set the LED and number you want to TRUE. Ex.

Wiimote1.Led1 = TRUE
Wiimote1.Led2 = FALSE
Wiimote1.Led3 = FALSE
Wiimote1.Led4 = FALSE

So this is also straight from the flickstart script, and you can turn on or off LED lights based on assigning the value to true or false. So any LED's that are assigned true will be on, any that are assigned false will be off. I hope to make a little running LED light script where the LED's actually work like chasing Christmas lights, but that is for another time :) So with that, you should have an idea of all of the things you can do with the different variables that you can assign to the Wiimote. BUT! There is still more that you can do :).

You can also create variables to use in your program. For example

Key.c = var.C

That creates a variable C which you can use for anything you want to. Why is this important? Well lets say you only want something to happen with a specific action, like oh flicking your hand straight down while pressing the B button? Now if any of you have used the flickstart script, you've experienced the code doing this, however this is how it works, but I will start with a more basic example.

if(Wiimote1.B) then
var.B = Wiimote.B
endif

key.b = var.b

So now anytime I press the B button, it is assigned to the letter B, however it wont' trigger until I press the B button. Now that seems silly if your only doing something you could have done higher up, but what about this...

var.yOffset = -37
var.yRot = Wiimote.RawForceY + var.yOffset

if var.yRot > 65 then
var.B = Wiimote.B and not (Wiimote.A or Wiimote.Minus or Wiimote.Home or Wiimote.Plus)
else
var.B = false
endif

Key.v = var.B

If you have looked at the flickstart code, then you'll see that this is from that. Basically it starts off making a variable var.yoffset which helps to center the Wiimote right I am assuming, and then makes a variable which gets a force of the Wiimote in the Y direction (or the up/down direction). Then we get to the if statement, so if this force is greater then 65, then the variable B (which you can see at the bottom) is assigned to the letter v, which is the letter that will start a track in Traktor. Otherwise, the variable B is just set to false, which means it's pretty much set to nothing. So you can press the B button all you want and it will do nothing until you do it with a flick at a certain rate. So hopefully that makes some sense, if not here is one other way of explaining it.

var.YRot is the force of the wiimote being flicked up or down. When it exceeds 65, then the B button is assigned to the letter v. However, once that isn't the case anymore then it is assigned to false, which is basically nothing. Now if that still doesn't make sense, ask or someone else can attempt to explain it better and I'll edit my post to add it in :).

Now what's that other stuff at the end of the line in the if statment?

if var.yRot > 65 then
var.B = Wiimote.B and not (Wiimote.A or Wiimote.Minus or Wiimote.Home or Wiimote.Plus)

I'm hoping the first part makes sense, the var.B = Wiimote.B, but the second half "and not (Wiimote.A or Wiimote.Minus or Wiimote.Home or Wiimote.Plus)" simply says to not assign that value to any of the other buttons. It is a simple as that. I have a different way of doing it with the accelerometer which may just be good to post here as another example of what you can do. So if you need an explanation, just post below, but here is my code with my comments

//Getting Wiimote Positing and values so when change occurs it's detected. The basic theory here is since the script loops
//Var.C will be assigned to the old accelerometer value, then value A will be assigned to the current one

var.C = Var.A
var.A = Wiimote2.gy

//When Var.A becomes more then Var.C the wiimote has hit bottom and started to go up. Post on the forum if you need more of an explanation

if var.A < -1 && var.C < Var.A{ //var.A < -1 is sensitivity, higher the number the more sensitive to starting
var.C100 = Wiimote2.A and not (Wiimote2.B or Wiimote2.Minus or Wiimote2.Home or Wiimote2.Plus)
else
var.C100 = false
endif

Midi.ByteControl100 = var.C100

Now the only thing that is really new, is the Midi.ByteControl100, so what the heck is that? Well instead of setting the variable var.C100 equal to a letter, I am assigning it to be equal to a midi value, as I do my Wiijing using midi as I have a bit more freedom to do different things. So that's all for now, but I'll post next time on what some of the different commands do (like Wiimote1.gy) and how you can use them in different ways.
Mobile Party and Wedding DJ for Manteca California