title: Send a single signal from Python to Arduino for a range of values
body: <p>Python Code:</p>
  
  <pre><code>ser = serial.Serial("COM1", 19200, timeout=5)
  time.sleep(2)
  while True:
      # ... img processing
      faces = face_cascade.detectMultiScale(gray, 1.3, 5)
  
      detected = False
  
  
      for (x, y, w, h) in faces:
          # ... faces processing
          detect_face=x
  
  
          print 'face distance: ', detect_face
          if 80 &lt; detect_face &lt; 100:
              if detected:
                 pass
              else:
                 print '1'
                 detected = True
          else:
              if detected:
                 print '2'
                 detected = False
              else:
                 pass
  </code></pre>
  
  <p><code>detect_face</code> value:</p>
  
  <pre><code>face distance:  123
  face distance:  112
  face distance:  99
  1
  face distance:  95
  1
  face distance:  64
  face distance:  68
  face distance:  73
  face distance:  80
  face distance:  80
  face distance:  88
  1
  face distance:  88
  1
  face distance:  88
  1
  face distance:  97
  1
  face distance:  102
  face distance:  112
  </code></pre>
  
  <p>Arduino code:</p>
  
  <pre><code>void loop() {
    if (Serial.available() &gt; 0) { 
      incomingBit = Serial.read();
      switch (incomingBit) {
        case '1':
            Servo1.write(0); 
            delay(1000); 
  
            Servo1.write(90); 
            delay(1000); 
  
            Servo1.write(180); 
            delay(1000); 
            //exit(0);
         break;
  
         case '2' :
           Servo1.write(0);
         break;
  </code></pre>
  
  <p>Now what I want to do is to send a 'single' signal '1', each time <code>80 &lt; 
   detect_face &lt; 100</code>. For example, when <code>detect_face</code> is <code>104,95,80,80,98,100,...</code> <code>ser.write('1')</code> is sending signal 4 times as a result my servo connected to Arduino is moving 4 times in a loop. What i want is for <code>detect_face</code> values <code>104,95,80,80,98,100</code> send a signal to arduino only one time not 4 times. How can I do that on the Python side? or even at Arduino side?</p>