4 ms·
I've decided to put the timeOn and timeOff values into an array which I will manually factor the best values for power level. It's not a super elegant algorith
by sigmaprimus 6y ago
I've decided to put the timeOn and timeOff values into an array which I will manually factor the best values for power level.
It's not a super elegant algorithmic solution but will do everything I need for now, and the array is relatively small at 200 indices.
- sigmaprimus 6y agoI probably should have started with working it out manually, working through the numbers made the function obvious. Here is the what I believe will work: void powerCalc(){ if (powerLvl < 1) { powerLvl = 1; } if (powerLvl > 99) { powerLvl = 99; } if (powerLvl < 51) { // To avoid On/Off times below 20ms I made 2 inverted functions controlled by an if then else timeOn = 20; timeOff = (2000 - (powerLvl * 20)) / powerLvl; } else { timeOff = 20; timeOn = (2000 - ((100 - powerLvl) * 20)) / (100 - powerLvl); } }