trouble blinking an led

Discuss Lemur and share techniques.
Post Reply
XedMada
Newbie
Posts: 8
Joined: 20 Feb 2012 07:38

trouble blinking an led

Post 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);
}
axel_liine
Liine Staff
Posts: 126
Joined: 14 Dec 2011 12:12

Re: trouble blinking an led

Post 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
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: trouble blinking an led

Post 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
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
Post Reply