Page 1 of 1

trouble blinking an led

Posted: 08 Aug 2012 05:00
by XedMada
I've got a nice little function attached to an LED I stick in the corner of every screen to keep an eye on the battery. It works well, but i'd like it to blink when it gets under 10%. I thought I could just set a sin on the light attribute, but it doesn't seem to be working. Any suggestions?

Code: Select all

//note: battery only seems to update at 5% intervals.
//green if above 50%
if(battery<=1 && battery>=0.49){ 
	setattribute(BatteryIndicator,'color',RGB(0,1,0));
}

//yellow if between 50% and 20%
if(battery<=0.5 && battery>=0.21){ 
	setattribute(BatteryIndicator,'color',RGB(1,1,0));
}

//red if 20% or less
if(battery<=0.2){ 
	setattribute(BatteryIndicator,'color',RGB(1,0,0));
}

//pulse is 10% or less
if(battery<=0.1){ 
	setattribute(BatteryIndicator,'light',sin(time*10)*2);
}

Re: trouble blinking an led

Posted: 08 Aug 2012 07:22
by axel_liine
Hi,
Nice idea for a script ! Your only mistake here is that the 'light' value of Leds (and actually all objects that have a controllable light) is actually not an attribute, but an expression, just like x, y, z for Multiballs, etc.
You can recognize an expression from an attribute in that it has an editable field in the Properties/Behaviour where you can input a short one-line script, and it can be mapped to incoming MIDI/OSC.

So that would make the end of your script like :

Code: Select all

if(battery<=0.1){ 
   BatteryIndicator.light = sin(time*10)*2;
}
Note that you could also do it all from the 'light' field in the Leds properties, and use a one-line condition.

light =

Code: Select all

battery <= 0.1 ? sin(time*10)*2 : 0

Re: trouble blinking an led

Posted: 08 Aug 2012 09:50
by Macciza
Another thing to keep in mind is that light goes from 0 (unaffected) to white . . .
So this will flash for the color to white - negative offset to light will make it do black to color . . .

The other option of course is that you can modulate the 'value' (off,on) of the Led instead to get it pulse the different colors
Set the background to black and you get the blinking foreground color

Cheers
MM