It is currently July 4th, 2022, 6:27 am

Map 3000-6500 to 0-255

General topics related to Rainmeter.
HitFrostbite
Posts: 15
Joined: May 20th, 2022, 1:34 pm

Map 3000-6500 to 0-255

Post by HitFrostbite »

Hi,
I've created a skin to control the brightness and color temperature of my smart bulb via command line.
But the problem is that the values to control the color temperature range from 3000-6500,
I have set a scroll function using clamp to achieve that:

Code: Select all

MouseScrollDownAction=[!SetVariable Brightness (Clamp(#CT#-#CTIncrement#,3500,6500))][!CommandMeasure SetCT "Run"] [!Update]
MouseScrollUpAction=[!SetVariable Brightness (Clamp(#CT#+#CTIncrement#,3500,6500))][!CommandMeasure SetCT "Run"] [!Update]
But the x position of the slider on my skin needs to move from 0-255.

Is there any way to map the 3000-6500 to 0-255?

Thanks
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4779
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Map 3000-6500 to 0-255

Post by eclectic-tech »

HitFrostbite wrote: May 22nd, 2022, 12:51 pm Hi,
I've created a skin to control the brightness and color temperature of my smart bulb via command line.
But the problem is that the values to control the color temperature range from 3000-6500,
I have set a scroll function using clamp to achieve that:

Code: Select all

MouseScrollDownAction=[!SetVariable Brightness (Clamp(#CT#-#CTIncrement#,3500,6500))][!CommandMeasure SetCT "Run"] [!Update]
MouseScrollUpAction=[!SetVariable Brightness (Clamp(#CT#+#CTIncrement#,3500,6500))][!CommandMeasure SetCT "Run"] [!Update]
But the x position of the slider on my skin needs to move from 0-255.

Is there any way to map the 3000-6500 to 0-255?

Thanks
Divide your range by 256 to find a divisor of the brightness variable to use in your formula.

If your range is 3000 (according to your scroll formula: 6500-3500), then you can set the X value to X=(floor(#Brightness#/11.71875))

If you want the range to be 3500 (6500-3000), then set X=(floor(#Brightness#/13.671875))

Add DynamicVariables=1 to the meter to use the current value of #Brightness#.
HitFrostbite
Posts: 15
Joined: May 20th, 2022, 1:34 pm

Re: Map 3000-6500 to 0-255

Post by HitFrostbite »

Thanks I'll try it out.
HitFrostbite
Posts: 15
Joined: May 20th, 2022, 1:34 pm

Re: Map 3000-6500 to 0-255

Post by HitFrostbite »

eclectic-tech wrote: May 22nd, 2022, 1:31 pm Divide your range by 256 to find a divisor of the brightness variable to use in your formula.

If your range is 3000 (according to your scroll formula: 6500-3500), then you can set the X value to X=(floor(#Brightness#/11.71875))

If you want the range to be 3500 (6500-3000), then set X=(floor(#Brightness#/13.671875))

Add DynamicVariables=1 to the meter to use the current value of #Brightness#.
It worked!
Thanks a lot!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4779
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Map 3000-6500 to 0-255

Post by eclectic-tech »

:thumbup: