
Originally Posted by
tumbleweed
That's an interesting operation. Splitting the equation up into two parts for DIV32 seems to work...
Code:
LEDBrVal = ((compVal - 0) * (MaxDuty - MinDuty))
LEDBrVal = DIV32 (MaxADCVal - 0) + MinDuty
Is it safe to do something like that or would you suggest making the DIV32 statement simpler so that you know it immediately follows the multiplication (I don't know what the OP's intent for the " - 0" part of the above is for)?
I grabbed this scaling function from an Arduino library and was emulating that:
Code:
' Arduino Map function to emulate:
' ===============================
' map(value, fromLow, fromHigh, toLow, toHigh)
' long map(long x, long in_min, long in_max, long out_min, long out_max)
' {
' return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
' }
In general, the minimum brightness level is 0. But in this case, I only want to adjust the LED brightness between 50-100% duty cycle, so maybe I need to tweak that part as well.
Bookmarks