title: How to get a input that continuously gives data to output a single digit integer value
body: <p>To give a short summary of my project, it’s a smart parking system where I let a parking user know whether a parking lot is vacant or not. I’m implementing an XBee network containing 1 coordinator and 2 routers. I have two sensors, 1 sensor at the exit and 1 at the entrance. Those two sensors are the routers and whatever data they gather is being transmitted to the coordinator (output). The two routers have the same code which is:</p>
  <p>INPUT CODE (TRANSMITTING):</p>
  <pre><code>#include&lt;SoftwareSerial.h&gt;
  #define Sensor 8 
  
  void setup() {
  
  pinMode(Sensor,INPUT);
  Serial.begin(9600);
  
  }
  
  void loop()
  {
  
  bool Detection = digitalRead(Sensor);
  int carexit=1;
  
  if(Detection == HIGH)
    {
    Serial.println(&quot;Car Exit&quot;);
  
    Serial.write(carexit);
  
    }
  if(Detection == LOW)
    {
    Serial.println(&quot;Clear&quot;);
    }
  }
  </code></pre>
  <p>It’s a very simple code where it detects a car coming in or out. Since the two routers are the same we’ll use the sensor for the cars exiting. When I open the serial monitor, the word “Clear” will keep on being outputted continuously nonstop until detection is found which will show an output of “Car Exit” for about 3 seconds and then return to “Clear” continuously. This data is being transmitted to the coordinator. What I’m trying to do is take that continuous data and have the serial monitor at the coordinator input a single integer value. For example, at the entrance, the sensor will sense the car and transmit the data to the coordinator where it'll increment. The result will show something like this if there’s only 1 vacant slot available:</p>
  <p>Vacant slots: 1</p>
  <p>and when the car exits the router at the exit, it will transmit a code to the coordinator decrementing it:</p>
  <p>Vacant slots: 0</p>
  <p>So, the input(router) would be transmitting continuous data while the output(transmitter) will detect it and just register it for a single-digit value. The output code(receiving) by the way is shown below:</p>
  <p>OUTPUT CODE(RECEIVING):</p>
  <pre><code>#include &quot;SoftwareSerial.h&quot;
  
  // RX: Arduino pin 2, XBee pin DOUT.  TX:  Arduino pin 3, XBee pin DIN
  
  
  void setup()
  {
  
    Serial.begin(9600);
  }
  void loop()
  {
  
  
    if (Serial.available() &gt; 0)
    {
     
      Serial.write(Serial.read());
  
    }
  }
  </code></pre>
  <p>The output code is pretty simple as well. Let me know if there’s any possible way to implement what I’m trying to do and if there are any other details I left out, let me know as well.</p>
  <p>Thank you!</p>