3 ms·
I 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: vo
by sigmaprimus 6y ago
I 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);
}
}