albino001 Posted February 18, 2012 Share Posted February 18, 2012 Alrighty so I have the rest of this working with the arduino and stuff so the leds are just part of another function and all so heres what im trying to do, but cant find the right functions to multiply/divide and stuff like that. max number for ex is 250 Number changes from 250 to 0 100% of <MAX> is 250 95% of <MAX> is 237.5 ... 5% of <MAX> is 12.5 0% of <MAX> is 0 --- If <Num> equals 100% LED 1-20 on If <Num> equals 95% LED 1-19 on ... If <Num> equals 5% LED 1 on If <Num> equals 0% No LED on I figure ill just use a quick multiplication , say (250*.05) then a function like If <Num> is > or = to <Percentage1(being 5 %)> than turn led1 on If <Num> is < <Percentage1> turn led off ... If <Num> is > or = to <Percentage20(being 100%)> than turn led20 on If <Num> is < <Percentage1> turn led off I figure it might be easier mapping each percentage to its own led rather then if its 100 percent have led turn led 1-20 on and if (assuming its at 100%) the numbers are greater then percentages 19-0 then do nothing. Any help is greatly appreciated. Link to comment Share on other sites More sharing options...
themaskedwolf Posted February 19, 2012 Share Posted February 19, 2012 are u working with arduino code or autoit? if autoit u can use a switch to check for what ur wanting or a if statement exampleIf $max=< .05*250 then ; 1 is 100% .05 is 5% ect.... do this code here elseif $max=<.10*250 do this code here elseif $max=<.15*250 do this code here else do this endif Link to comment Share on other sites More sharing options...
qsek Posted February 19, 2012 Share Posted February 19, 2012 code example depending what you want as input: For $i = 1 To 100 ConsoleWrite($i&":"&floor(($i/10)*2) & @LF) next For $i = 1 To 250 ConsoleWrite($i&":"&floor(($i/250) * 20) & @LF) next Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Link to comment Share on other sites More sharing options...
albino001 Posted February 19, 2012 Author Share Posted February 19, 2012 Thank you everyone for the answers @themaskedwolf I am using autoit code, this works quite nicely thanks. @69255 Its not that im using 20 leds, i just needed 1 led per functions say 10 percent for led 2 ::: If $num >= ($max*10)/100 Then _CommSendString("2") ;On EndIf If $num < ($max*10)/100 Then _CommSendString("B") ;Off EndIf If thats not what you were meaning my bad very little understanding of autoit @qsek to be honest I only somewhat get what that code is doing. @everyone im getting data for this number, from another program, temperature of stuff, which constantly changes, cold warm warmer etc so i want to constantly refresh the data in the function, max doesnt need refreshed i set it myself just need the number to be refresh. Link to comment Share on other sites More sharing options...
qsek Posted February 19, 2012 Share Posted February 19, 2012 (edited) well, we gave you the formula for calculating. You can use this in 20 IF statements if you like. ; Example 1 $num = 47 ; input/temperature value $led = floor(($num/250) * 20); how much leds are on ConsoleWrite("LEDs on:" & $led & @LF) If 1 <= $led Then _CommSendString("1") ;On else _CommSendString("A") ;Off EndIf If 2 <= $led Then _CommSendString("2") ;On else _CommSendString("B") ;Off EndIf .... .... Or you can loop through every LED and check if its to be turned on or off: ; Example 2 $num = 47 ; input/temperature value $led = floor(($num/250) * 20); how much leds are on ConsoleWrite("LEDs on:" & $led & @LF) For $i = 1 To 20 ; go through LEDs 1 to 20 and set which are On or Off If $i <= $led Then ; if current LED <= LEDs On _CommSendString($i) ;On else _CommSendString(chr(64+$i)) ;Off, chr(65) = "A" EndIf next Func _CommSendString($sCom) ConsoleWrite($sCom & @LF) EndFunc I dont know if those ON/Off commands you send are the real one or just examples, but if you need capital letters to turn the LEDs off, chr would be the function you need here. You could even optimize this by only send commands to those LEDs that change, but that would require a more complicated code. Edited February 19, 2012 by qsek Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Link to comment Share on other sites More sharing options...
albino001 Posted February 19, 2012 Author Share Posted February 19, 2012 (edited) Ohh i get it now, and 250 was just a example number... i hope... Im gonna try this now.Any reason why, With just my current If $num >= ($max*50)/100 Then _CommSendString("1");on 1 EndIf If $num < ($max*50)/100 Then _CommSendString("A");off 1 EndIf If $num >= ($max*100)/100 Then _CommSendString("2");on 2 EndIf If $num < ($max*100)/100 Then _CommSendString("B");off 2 EndIf If $num <= ($max*0)/100 Then _CommSendString("B");off 2 _CommSendString("A");off 1 EndIf It takes ~10 seconds to read data, send strings, repeat. I no its not the read data part because i have this in a gui which updates every second, is it my math? This is a function btw, i call on this function when i click the "read" button i made. Oh and its still in testing using only 2 leds , one for 50 and up percent the other for 100 percent of the max Edited February 19, 2012 by albino001 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now