Move hall sensor secondly code into function.