How to Keep LED Flashing Until it gets a N?

i managed to get this gmail notification working, all I need is to get the LED to Flash until it gets the No (N) from the python script?

// led wired + to pin 12, resistor to positive +5v

int outPin = 13; // Output connected to digital pin 12
int mail = HIGH; // Is there new mail?
int val; // Value read from the serial port
void setup()
{
 pinMode(outPin, OUTPUT); // sets the digital pin as output
 Serial.begin(9600);
 Serial.flush();
 mail = LOW; // start off with lights out
}

void loop()
{
 // Read from serial port
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val, byte(0));

   if (val == 110) // n = 110 in dec
   {
     mail = HIGH;  // HIGH is off because led is connected to +5v on the other side
   }

   else if (val == 109) //109 = m in dec
   {
     mail = LOW; // LOW is on because led is connected to +5v on the other side
   }
 }

 // Set the status of the output pin
 digitalWrite(outPin, mail);
}

Search for "blink without delay" to see a good way to do it here. You just put it in your loop().

Thanks for the reply, i started with the 'Blink' example but no joy, will try 'Blink Without Delay'

Worked Thanks!

// led wired + to pin 13, resistor to positive +5v

int outPin = 13; // Output connected to digital pin 13
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; 
void setup()
{
 pinMode(outPin, OUTPUT); // sets the digital pin as output
 Serial.begin(9600);
 Serial.flush();
 mail = LOW; // start off with lights out
 }

void loop()
{
    unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = LOW;
    else
      ledState = HIGH;
    // set the LED with the ledState of the variable:
    digitalWrite(outPin, ledState);}
 // Read from serial port
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val, byte(0));

   if (val == 110) // n = 110 in dec
   {
     mail = LOW;  // HIGH is off because led is connected to +5v on the other side
   }

   else if (val == 109) //109 = m in dec
   {
     mail = HIGH; // LOW is on because led is connected to +5v on the other side
   }
 }

 // Set the status of the output pin
 digitalWrite(outPin, mail);
}

The so-called "blink without delay" procedure doesn't "block". It always runs in the same amount of time. It simply calls millis() and returns a bit value that is toggling every n milliseconds.

if(mail)
 flashState = (millis() & (1 << bitcolumn)) ? 1 : 0;
else
 flashState = 0;
digitalWrite(outPin, flashState);

Try values of 8 thru 11 for bitcolumn and pick a speed you like. Put this code in place of the digitalWrite() you have at the end of the loop. You will have to define flashState somewhere.

if (val == 110) // n = 110 in dec

The National Society for The Abolition of the Pointless Comment says

if (val == 'n')

Cheers for the help, here's the results

Here

Moderator edit: code tag swapped for url