Stop Command

(a) Your question has nothing to do with the section (Installation) that you have posted it in. It should be in programming questions where more programmers would see it.

(b) Map out your program on paper.

Your program is in three sections:

  1. Read serial port
  2. Loop until serial input == ON
  3. Loop until serial input == OFF

Sections 2 and 3 loop until the serial input in section 1 changes. But if you are in section 2 or 3 waiting for the serial input to change when do you leave to back to section 1 to get new input? You have built yourself a big catch-22 program. You can't read the serial input until it changes which can't be changed until you read it which can't be read until it changes which can't be changed until you read it which can't read until it changes............