LED turn on/turn off algorithm