void main() { adc_init(); DDRA &= ~((1 << PA0) | (1 << PA1)); DDRB |= (1 << PB0); while (1) { uint16_t counter = 50000; uint8_t refBit = 3; while (counter > 0) { counter--; refBit &= 1 + ((PINA & (1 << PA1)) >> 1); delay(39); } // is the refBit 1 or 2? => maskBit is 1 else 0 uint8_t maskBit = (refBit & 1 | (refBit >> 1) & 1); PORTB = PORTB & ~(maskBit << PB0); uint16_t strangeWaterLevelValue = get_adc(); if (strangeWaterLevelValue < 100) PORTB = PORTB & ~(1 << PB0); } }