title: Arduino detect OBD init sequence on digital pin
body: <p>I am developing an OBD simulator using an Arduino Uno so that I may then develop another Arduino to read the OBD data from the simulator.</p>
  
  <p>This is my first Arduino projectand I am find with all the serial comms but the one thing I cannot figure out is how to detect what is called the facinit sequence in my simulator.</p>
  
  <p>The fastinit / wakeup sequence consists of bringing the serial tx line high for a period > 300ms then low for 25ms and then high again for 25ms. At which point the OBD is awake and switches to 10400 baud.</p>
  
  <p>The code to simulate this from the OBD Tool side is shown below. Now I can read the TX line from the OBD simulator side and then check it after so many ms to see if it is maintaining the signal, but it could go up and down in the meantime. I believe there is a mechanism to detect a change in signals but I cannot figure it out</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  
  #define K_IN   D8
  #define K_OUT  D9
  
  SoftwareSerial obdSerial(K_IN, K_OUT);
  
  byte initStep = 0;
  unsigned long initTime = 0;
  
  setup() {
      initStep = 0;
      initTime = 0;
  }
  
  loop() {}
      unsigned long currentTime = millis();
  
      switch (initStep) {
          case 0: 
              initTime = currentTime + 300;
              initStep++;
              break;
          case 1:
              if (currentTime &gt;= initTime) {
                  digitalWrite(K_OUT, HIGH);
                  initTime = currentTime + 300;
                  initStep++;
              }
              break;
          case 2:
          case 3:
              if (currentTime &gt;= initTime) {
                  digitalWrite(K_OUT, (initStep == 2 ? LOW : HIGH));
                  initTime = currentTime + (initStep == 2 ? 25 : 25);
                  initStep++;
              }
              break;
          case 4:
              if (currentTime &gt;= initTime) {
                  // switch now to 10400 baud
                  obdSerial.begin(10400);
              }
              break;
      }
  }    
  </code></pre>