# Help With Functions

i’m trying to set a needle to show heart rate. i know how to set the rotation of images, but what i need help with is trying to figure out how to make the needle range from 50-160 instead of 0-240.

what i think i need to do is set floor and ceiling functions, but i have no idea how to use correct syntax. can anybody help or at least point to a tutorial. i’ve already been to the code lab page but i still can’t figure out how to write it.

TYIA

Actually no, floor and ceiling are functions to reduce decimal number to a whole number (lower or higher).
What you need to restrict the range of displayed values is clamp function.
Then you need to imagine the starting and ending positions for the hand.
Will it be turning a whole circle or portion of it? Will the starting value be on top or elsewhere?

Usually the hand resource images are drawn so, that the hand points up at 0° rotation and the rotation angle counts clockwise (from top to the right).
General formula for any such hand would look like
clamp([tag], min, max)*(AngleAtMax-AngleAtMin)/(max-min)+AngleAtMin

for example here the HR hand going from 270° at 50 BPM to 468° (equal to 108°) at 160 BPM

3 Likes

THANK YOU SO VERY MUCH!

i have no idea how to parse many of these codes, i usually just stick with the simple ones. thanks to your example i got it working exactly the way i want it to on a 240º dial.

thanks again

1 Like