From WiiLi
//////////////////////////////////////////////////////////////////////
//// Balance the Leds v 1.01
/// Originally created and coded by TiagoTiago
//////////////////////////////////////////////////////////////////////
//new version, all that was changed was the parameters, now it is more responsive (but perhaps a bit harderd)
// roll the Wiimote on your hands (with it placed on a flat surface will make it a bit too easy)
// to try to balance the leds to the middle position (with the middle leds lit)
// if you manage to hold the leds there till the wiimote vibrates you win :)
Wiimote1.Frequency= 1000 hz// the frequency of thw inning sound on the speaker of the wiimote
//how many loops of the script with the middle leds lit it takes to win
var.Won= 300 // make smaller to make it easier
var.maximp= 20// the maximum speed the leds will move , the smaller the easier
var.Drag= 100 // the drag on the movement, lower values will make it easier, but too low and the thign won't move
//Setuping the data for the conversion between position and led lighting
var.maxled = 140
var.frac= var.maxled/ 7
///////
if(!var.Reset)then //it shakes the thing to start a new game
var.curpos = Random(100) // random position
var.Impulse= RandomRange(var.maximp/2,var.maximp) * Sign(RandomRange(-1,1)) //random impulse
if (var.Impuls= 0) then var.Impulse= RandomRange(1, var.maximp)// if the rnadom generated a zero generate itagain in a way it won't be zero
var.Reset=1 //clear the reset request
endif
var.adder= Maprange(Wiimote1.Roll,-90, 90, -.5, .5) //gets the data on how much "force" you are applying
var.impulse = var.impulse+ var.adder //Applies the force to the impulse
var.Impulse= var.Impulse- (var.Impulse/ var.drag) //apply drag effect
if (var.Impulse> var.maximp)then var.Impulse = var.maximp //if the impulse is too much set it to the maximum allowed
if (var.Impulse< -var.maximp)then var.Impulse= -var.maximp //if it is too much on the other direction do the same (but on the same direction
var.curpos= var.curpos+ var.impulse// apply the momentum on the thing
if var.curpos> 100 then //if the position is too far to the left
var.curpos= 100 //set it to the maximum allowed
var.Impulse= var.Impulse* -1// and bounce it
endif
if var.curpos< 0 then //if the position is too far to the right
var.curpos= 0 //set it to the maximum allowed
var.Impulse= var.Impulse* -1 // and bounce it
endif
var.ledpos = MapRange(var.curpos,0, 100, 0 , var.maxled) // convert from position to led position
if (var.Ledpos < var.frac*1) then// if in the range of these leds lit them
Wiimote1.Leds= 1
elseif (var.Ledpos < var.frac*2) then
Wiimote1.Leds= 1+2
elseif (var.Ledpos < var.frac*3) then
Wiimote1.Leds= 2
elseif (var.Ledpos < var.frac*4) then
Wiimote1.Leds= 2+4
elseif (var.Ledpos < var.frac*5) then
Wiimote1.Leds= 4
elseif (var.Ledpos < var.frac*6) then
Wiimote1.Leds= 4+8
elseif (var.Ledpos < var.frac*7) then
Wiimote1.Leds= 8
endif
if ((var.Ledpos < var.frac*4) AND (var.LedPos> var.frac*3)) then //check to see if it is centered
if (var.alreadYinthemiddle) then// if it was already centered
var.winning= var.winning+1 //add points
if (var.Winning>= var.won)then //if it is in the middle for enough time
Wiimote1.Rumble= True //vibrate to let the player know they won
Wait 500ms
Wiimote1.Rumble= False
var.Reset= 0 //asks for a new game
var.alreadYinthemiddle= FALSE //start this over
var.winning= 0 //and clear the points
endif
else //if it just got in th emiddle
var.alreadyinthemiddle= TRUE //let the code know that it is in the middle
endif
else //if not in the middle
var.winning= 0 //Clears the points
endif
Wiimote1.Volume= MapRange(var.winning,0, var.won, 0, 100%) //sound the wiimote speaker, louder means closer to winning