title: Arduino microphone/AMB decoder combination gets interrupted
body: <h1>Microphone readout gets randomly interrupted</h1>
  <p>I have a microphone hooked up to my Arduino on a Serial hardware port 2.
  <a href="https://sigrok.org/wiki/Colead_SL-5868P" rel="nofollow noreferrer">https://sigrok.org/wiki/Colead_SL-5868P</a></p>
  <p>I receive data from the microphone by sending 0x20 to it. The following functions read out it's data.</p>
  <p>FlushMic1 is a function to flush out the Serial2 buffer, so we can read out the correct data from the buffer.</p>
  <pre><code>String getMic1()
  {
    String valueMic;
    
    if(flushedMic1())
    {
      Serial2.write(0x20);
  
      while (Serial2.available() &lt;= 10){;}
      valueMic = &quot;&quot;;
      
      for (int i = 0; i &lt; 10; i++)
      {
        int data = Serial2.read();
        valueMic += String(data);
      }
    } 
    return valueMic;
  }
  
  bool flushedMic1()
  {
    bool returnBool = false;
    while(Serial2.available())
    {
      Serial2.read();
      returnBool = true;
    }
    return returnBool;
  }
  </code></pre>
  <p>On another port I have a transponder loop connected, to measure passing transponders.</p>
  <p>If a transponder passes it sends char to the Serial Hardware port 1. It can be detected if it includes a '@'.</p>
  <pre><code>bool isTransponderPassing()
  {
    char data = Serial1.read();
  
    if (data == '@')
    {
      return true;
    }
    return false;
  }
  </code></pre>
  <p>Running the getMic1() function in a loop works perfectly fine. If the : if(isTransponderPassing())  is used in the in main loop I sometimes get the correct data, sometimes false data, when I receive false data, the entire program gets interrupted, which propably fills the buffer with 16's and that's why we receive 16's.</p>
  <p>Who knows where my program can get stuck?</p>
  <pre><code>
  void setup()
  {
    // Starts the serial monitor
    Serial.begin(2400);
  
    // Starts Serial monitor of AMB decoder
    Serial1.begin(9600);
  
    // Starts Serial monitor of microphone 1
    Serial2.begin(2400);
  }
  
  void loop()
  {
    Serial.println(Serial2.available());
    Serial.println(Serial1.available()); 
    
    if(isTransponderPassing())
    {
      Serial.println(getMic1());  
    }
  }
  </code></pre>