// Type your program here, or click the GUI tab to autogenerate it!
var.LightRate = 150

Wiimote.Rumble = Wiimote.Home;
Mouse.LeftButton = Wiimote.A;
Mouse.RightButton = Wiimote.B;
Wiimote.Led1 = Wiimote.One;
Wiimote.Led2 = Wiimote.Two;

if Nunchuk.ZButton then
Screen.ScrollX += Wiimote.Nunchuk.JoyX*16;
Screen.ScrollY += Wiimote.Nunchuk.JoyY*16;
endif

if pressed(Nunchuk.CButton) then
Screen.ScrollX = 0
Screen.ScrollY = 0
endif


debug = 'Battery = ' + Wiimote.Battery
//Mouse.CursorPosY = (Wiimote.Pitch-(Wiimote.Pitch/2))/-8000000
Mouse.CursorPosX += Wiimote.Nunchuk.JoyX*16;
Mouse.CursorPosY += Wiimote.Nunchuk.JoyY*16;

If Wiimote.Plus Then
Wiimote.Mute = 0;
Wiimote.Frequency = 1046.50;
Wiimote.Volume = Wiimote.Battery/500;
ElseIf Wiimote.Minus Then
Wiimote.Mute = 0;
Wiimote.Frequency = 1046.50;
Wiimote.Volume = 0.25;
Else
Wiimote.Mute = 1;
EndIf

If Wiimote.Down Then
Mouse.CursorPosY += 6;
EndIf
If Wiimote.Up Then
Mouse.CursorPosY -= 6;
EndIf
If Wiimote.Left Then
Mouse.CursorPosX -= 6;
EndIf
If Wiimote.Right Then
Mouse.CursorPosX += 6;
EndIf


//Light FX
If (var.LED >= (var.LightRate/4)*0 && var.LED < (var.LightRate/4)*1) Then
If (!Wiimote.Led1) Then
Wiimote.Led1 = 1
Wiimote.Led2 = 0
Wiimote.Led3 = 0
Wiimote.Led4 = 0
EndIf
ElseIf (var.LED >= (var.LightRate/4)*1 && var.LED < (var.LightRate/4)*2) Then
If (!Wiimote.Led2) Then
Wiimote.Led1 = 0
Wiimote.Led2 = 1
Wiimote.Led3 = 0
Wiimote.Led4 = 0
EndIf
ElseIf (var.LED >= (var.LightRate/4)*2 && var.LED < (var.LightRate/4)*3) Then
If (!Wiimote.Led3) Then
Wiimote.Led1 = 0
Wiimote.Led2 = 0
Wiimote.Led3 = 1
Wiimote.Led4 = 0
EndIf
ElseIf (var.LED >= (var.LightRate/4)*3 && var.LED < (var.LightRate/4)*4) Then
If (!Wiimote.Led4) Then
Wiimote.Led1 = 0
Wiimote.Led2 = 0
Wiimote.Led3 = 0
Wiimote.Led4 = 1
EndIf
Else
var.LED = -1
EndIf
var.LED += 1

