при первом вызове bat_check() гистерезис = 0, т.е отключен
дальше гистерезис = 10, ну или сколько надо
Код: Выделить всё
void bat_check(void)
{
static u8 hysteresis;
static u8 dutycycle;
u8 adc_raw = bat_getvoltage();
if (adc_raw > 210) { //MAX - 211
BlueLight_ON();
dutycycle = 0;
} else
if (adc_raw <= (210 - hysteresis) && adc_raw > 183) { //210 - 184
BlueLight_OFF();
dutycycle = 5;
} else
if (adc_raw <= (183 - hysteresis) && adc_raw > 150) { //183 - 151
BlueLight_OFF();
dutycycle = 95;
} else
if (adc_raw <= (150 - hysteresis)) { //150 - MIN
BlueLight_OFF();
dutycycle = 0;
}
hysteresis = 10;
static u8 timer;
if(++timer >= 100) timer = 0;
if(dutycycle && timer > dutycycle) RedLight_ON();
else RedLight_OFF();
} primuss3.com



