Help with math for progress bar.

Get help with using AutoHotkey and its commands and hotkeys
x32
Posts: 98
Joined: 25 Nov 2016, 16:44

Help with math for progress bar.

16 Jan 2019, 19:26

I'm needing to do some math for a progress bar but am unable to wrap my head around it. I'm reading the input of a temperature sensor but the input is high numbers for low temps and low numbers for high temps.

For instance,

Code: Select all

Temp of 34c sensor returns 380.
Temp of 4c sensor returns 660
So I need to convert these numbers for a progress bar that will reed 0c to 100c. (or get it in the ballpark)

Who here is good at math?

Thanks

Edit:
With Arduino, there is a "Map" function for changing the input to match the expected output.

Code: Select all

value = map(value, 0, 1023, 0, 255);
Is there a similar function in AHK?
swagfag
Posts: 2528
Joined: 11 Jan 2017, 17:59

Re: Help with math for progress bar.

16 Jan 2019, 19:55

collect data
put ur data in excel
make a scatter plot
find the equation for ur trendline
use the formula in ahk
x32
Posts: 98
Joined: 25 Nov 2016, 16:44

Re: Help with math for progress bar.

16 Jan 2019, 20:18

Here's what I've been able to Google. It would be great if someone could let me know if I'm on the right track here.

Code: Select all

Get1:
Val := YoctoKnob_ButtonVal(ModSN,1)
input := -Val

value := map(input, -1023, 0, 0, 255) ;
GuiControl , , tempbar, %value%
GuiControl , , temptext, %value%
Return

map(X,A,B,C,D)
	{
	Y := (X-A)/(B-A) * (D-C) + C
	Return, %Y%
	}
So I converted the input from the sensor to a negative number so the scale would run the right direction, i.e. lower numbers now represent lower temps. This calculation, I found with Google, maps the input from the sensor (assuming the sensor values are 0 to 1023) to 0 to 255 for the progress bar.

Does this look correct?
swagfag
Posts: 2528
Joined: 11 Jan 2017, 17:59

Re: Help with math for progress bar.

16 Jan 2019, 21:47

who knows. dont u have a spec sheet for the sensor? map is a linear transformation. 36C: 380 and 4C: 660 dont look linear to me. then again, without revealing specific details about the sensor, u cant tell for sure

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, flyingDman, MIRKOSOFT, Monoxide3009 and 105 guests