diff --git a/src/load/load.c b/src/load/load.c index 3d559e5..f31c9d6 100644 --- a/src/load/load.c +++ b/src/load/load.c @@ -79,13 +79,18 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin) void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin) { uint16_t val = sample_adc(adc_pin); - - if(is_valid_load(val) && !portb_disabled[adc_pin]){ + if(portb_disabled[adc_pin]){ + RegEdit_ClearBit((void *) &PORTB.OUT, out_pin); + } + else if(!is_valid_load(val)){ + RegEdit_ClearBit((void *) &PORTB.OUT, out_pin); + portb_disabled[adc_pin] = true; + } + else if(is_below_target(val)) { RegEdit_SetBit((void *) &PORTB.DIR, out_pin); RegEdit_SetBit((void *) &PORTB.OUT, out_pin); } else{ RegEdit_ClearBit((void *) &PORTB.OUT, out_pin); - portb_disabled[adc_pin] = true; } }