user47386: I'm trying to make a tuner. 3 LEDs are connected to the Arduino board, each one corresponding to one situation (too high, low or correct).
Python handles the detecting of a note according to the mic input, and determines which led should be turned on, but as it's a live tuner, Python sends the information pretty fast.
I've figured out how to turn a led on one at a time and keep it on as long as the input doesn't change, but it only works at a low speed when I do it manually, with a Python program like this :
code=1
while code!=0:
    code=input("Code?")
    ser.write(code.encode('utf-8')) 

If I try it with a Python code such as :
code= '5'
while 1:
ser.write(code.encode('utf-8'))

then the LEDs just stay off.
Here is my Arduino Code :
int hauteur = 0;

void setup() {
    pinMode (2, OUTPUT); //red pin
    pinMode (6, OUTPUT); //green pin
    pinMode (5, OUTPUT); //yellow pin
    Serial.begin(9600);
}

void loop() {
    if(Serial.available ()) {
        hauteur = Serial.parseInt();

        while (hauteur==2) {
            (digitalWrite(2,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(2,LOW);

        while (hauteur==5){
            (digitalWrite(5,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(5,LOW);

        while (hauteur==6){
            (digitalWrite(6,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(6,LOW);

        Serial.flush();
    }
}

If 2, 5 or 6 are received with enough time in between them, then the board does what it's supposed to do and turns on the according LED. How can I reduce that necessary lapse of time to get a real time change of lights like a live tuner?

user37622: You don't need to parseInt for one digit. Use Serial.read(). 
  hauteur = Serial.read() - 48; // 48 is ascii code of '0'

or better send bytes from python, not digit characters

47386: <p>I'm trying to make a tuner. 3 LEDs are connected to the Arduino board, each one corresponding to one situation (too high, low or correct).</p>

<p>Python handles the detecting of a note according to the mic input, and determines which led should be turned on, but as it's a live tuner, Python sends the information pretty fast.</p>

<p>I've figured out how to turn a led on one at a time and keep it on as long as the input doesn't change, but it only works at a low speed when I do it manually, with a Python program like this :</p>

<pre><code>code=1
while code!=0:
    code=input("Code?")
    ser.write(code.encode('utf-8')) 
</code></pre>

<p>If I try it with a Python code such as :</p>

<pre><code>code= '5'
while 1:
ser.write(code.encode('utf-8'))
</code></pre>

<p>then the LEDs just stay off.</p>

<p>Here is my Arduino Code :</p>

<pre><code>int hauteur = 0;

void setup() {
    pinMode (2, OUTPUT); //red pin
    pinMode (6, OUTPUT); //green pin
    pinMode (5, OUTPUT); //yellow pin
    Serial.begin(9600);
}

void loop() {
    if(Serial.available ()) {
        hauteur = Serial.parseInt();

        while (hauteur==2) {
            (digitalWrite(2,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(2,LOW);

        while (hauteur==5){
            (digitalWrite(5,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(5,LOW);

        while (hauteur==6){
            (digitalWrite(6,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(6,LOW);

        Serial.flush();
    }
}
</code></pre>

<p>If 2, 5 or 6 are received with enough time in between them, then the board does what it's supposed to do and turns on the according LED. How can I reduce that necessary lapse of time to get a real time change of lights like a live tuner?</p>
 37622: <p>You don't need to parseInt for one digit. Use Serial.read(). </p>

<pre><code>  hauteur = Serial.read() - 48; // 48 is ascii code of '0'
</code></pre>

<p>or better send bytes from python, not digit characters</p>
