promo
GlovePie Tutorial 2

GlovePie Tutorial Section 2


So in the last section, I talked about the basic Hello World! program which uses the debug, and I bet a lot of you are saying "Why in the heck did he do that? Isn't there really no point to the whole debug thing to make scripts? I just want to dj!!!" Well, be calm my djing friend, the debug is possibly one of your most powerful tools because it allows you to see if what you want to do is actually working, and also to get information from the Wiimote to make sure that it is also working right.

So on that note, how about we check if your Wiimote is turned on and what the Battery level is:

debug = "Wiimote On:" + Wiimote1.Exists + " Wiimote Battery Level:" + Wiimote1.Battery

The first part of the code puts up the text Wiimote On: then next to it, will be True or False based on whether or not you've ever connected your Wiimote to the computer. The second will put up Wiimote Battery Level with a number from 0-192 (192 being a full battery) if your Wiimote is turned on. Also notice that each time you want to add something new, you have to add a plus sign for that "thing", and also notice that with Wiimote battery Level you have to add a space before it or all the words and numbers will run together. So this is just a basic example, but here is a bit more useful one

debug = "Wiimote Roll:" + Wiimote1.Roll

So what this will put out is whatever degree Wiimote1 is at. It’s fun to play with an roll the Wiimote left or right to see the different numbers you can get (Roll is how much the top is tilted towards the right. It is -180 or +180 when the Wiimote is upside-down, -90 when it is on its left side, +90 when it is on its right side. and 0 when it is flat.) But this can be especially important to display different information which the Wiimote is sending out as it can tell you if you have a problem with your Wiimote (like it not being turned on as I’ve done before :P) or if there is a problem in your coding. So the debug tool can be very, very powerful to both tell you what is going on and also to figure out different problems that are occurring.

So let me show you an example of testing something like that. Below is a section of code, which when you press the A button on the Wiimote, it will say, “I am A! Hear me roar!” while the rest of the time it will output “Who is A?” in the debug section.

debug = "Who is A?"

if(Wiimote1.A) then
debug = "I am A! Hear me roar!"
endif

So if you run this code, and then hold down the A button, you can watch the text in the debug section change from “Who is A?” to “I am A! Hear me roar!” and then it will change back again after you let go of the A button. So this shows three things. First, you can use the debug to tell if something happens, like this example of pressing the A button. This is really important because later on you may activate some FX and want to do it while you have the Wiimote at a certain angle and rolled a certain way, but it won’t work for some reason. Doing something like this will help you to check and see if the code you want to run is actually running. So another way to think of it is if I had this section of code

if (Wiimote1.A) then
var.C92 = 127
var.C12 = MapRange(Wiimote1.Roll, -90 degrees,90 degrees, 0,127)/127
var.C13 = MapRange(Wiimote1.Pitch, -90 degrees,90 degrees, 0,127)/127
var.C1 = MapRange(Wiimote1.SmoothRoll, -90 degrees,90 degrees, 60,60)/127
else
var.C92 = 0
var.C1 = 0
endif

which is taking values from the Wiimote and assigning them to different midi channels, if it wasn’t working in Traktor (or with my Kaoss Pad which is what it’s really supposed to be working with), I could check and see if the program is recognizing if I am pressing the A button down by simply adding the lines of code that I used in the previous example. So it would end up looking something like this.

debug = "Who is A?"

if (Wiimote1.A) then
debug = "I am A! Hear me roar!”
var.C92 = 127
var.C12 = MapRange(Wiimote1.Roll, -90 degrees,90 degrees, 0,127)/127
var.C13 = MapRange(Wiimote1.Pitch, -90 degrees,90 degrees, 0,127)/127
var.C1 = MapRange(Wiimote1.SmoothRoll, -90 degrees,90 degrees, 60,60)/127
else
var.C92 = 0
var.C1 = 0
endif

So then if my code still wasn’t working, I could at least know that it was getting into the if statement clause I have in my code. Second, this starts to show us about if statements. I had tried to figure out what I should explain first, but I think the debug is good to understand because you can actually see what’s going on. With most of the code you use, you won’t actually know what’s going as GlovePIE doesn’t tell you any information without using the debug statement. So just remember if you want to see what’s happening with something, use the debug statement, it’s your friend. But if statements! That’s a horrible sentence :P, however if statements are pretty much the main thing I’ve used and that I’ve seen others use in GlovePIE. They are your most powerful asset as they allow you to have things happen when something else does. For example, lets look at the simple A button test we had at the beginning:

debug = "Who is A?"

if(Wiimote1.A) then
debug = "I am A! Hear me roar!"
endif

In this, GlovePIE is waiting to see if the A button is pressed, and since the program loops constantly (as I talked about in Part 1, and is the third important thing illustarated by this) GlovePIE is just waiting to see if that happens. So as soon as the A button on Wiimote1 is pressed, then the debug changes. It’s just that simple. But you can have other things happen too, for example if you add something for the B button…

debug = "Who is A?"

if(Wiimote1.A) then
debug = "I am A! Hear me roar!"
else if(Wiimote1.B) then
debug = “I’m B! Not A!”
endif

This code will make it so if you press the A button, one thing happens, and if you press the B button then something else happens. And since the program is always looping (sorry for the repetition, but that I think is the hardest thing to understand) then it is always checking, is the A button being pressed? Is the B button being pressed? And if either of those are true, then it will do whatever the section of code under that if statement is. So there is the beginning intro to if statements. In part 3 I’ll talk more about assigning variables, what that means and how that works with GlovePIE, and if we’re lucky, I’ll even show how flickstarting works…but that may have to be part 4 :)

One last thing, whenever I post code here it seems to not look very tidy (I have things spaced out a certain way) so if you are having a hard time making sense of it the try to do some more research online about Glovepie, there are alot of resources on Google to help you out.