I have a variable I am using called setPoint. however I want this set point to be a range of numbers rather than a rigid number. so is there a way to set a variable to +/- 10 % or a range of numbers..
I know this is not correct syntax but i am trying to convey and idea..the result i am looking for is
I am controlling high power leds. I am trying to add a temperature control loop. the loop is fast and depending on conditions can cause unwanted flicker. I know there are several ways to do this.
so.. I have a simple temp sensor resistor divider that i am reading and testing against.
i am thinking to a set point that is +/- 10 % or like you said testing to see if the read from the sensor is within +/- % of the setPoint.
i am guessing that is the way to go?
how do i test if a number is between this and this? in my case 694 and 707 ?
I know this is simple for some but im new and simple minded.
You can have two variables, one to hold the setpoint and another to hold the percentage or fractional range, or use them to store the upper and lower limit.
Yes - this calculation will kill you pretty quickly on a UNO or similar 16 bit for a int architecture if value is above 3277 and range is 10 for example.... value * range / 100
I would writevalue * range / 100.0 to be on the safer side and tell the compiler to perform the math using float instead of int and cast the result
(that being said nice usage of OOP - but probably over the head of newbies)
I had been looking for a way to make a variable = a number +/- a percentage. once UKHeliBob
replied and said nope variables can only hold one value. I considered using an array.. like
is a value = a number in this array.
then thought more about the and thought about testing for between this and this and by the time i had figured out that is probably the way to go,, all these answers..