Simple L.E.D loop

Hi Guys,

I am trying to flash the L.E.D on pin13. The loop count comes from a number I enter in the "Serial Monitor". So, in other words, the pin13 L.E.D must flash the number I enter in the "Serial Monitor" ... Also, it prints the number I enter and the count number to the "Serial Monitor".

However, it seems to flash 51 times and then stop ... :frowning: ... Somewhere I have made a BIG boo-boo ... :slight_smile: ...

Here is the code:

##############################

int ledPin = 13;
int ledCount = 0 ;

void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts serial data
}

void loop()
{

if (Serial.available() > 0)
{
int inByte = Serial.read(); // waits untill somthing is typed

while ( ledCount != inByte )
{
digitalWrite(ledPin, HIGH);
delay(500) ;
digitalWrite(ledPin, LOW);
delay(500) ;

if ( ledCount == inByte )
{
exit ;
}
else
{
ledCount++ ;
}

Serial.print (inByte) ;
Serial.print (" ") ;
Serial.print ( ledCount ) ;
Serial.println ("") ;
}

}
}

##############################

Hope you can help ...

Danny

51 is ASCII '3'

Please use code tags when posting code

int ledPin = 13;

void setup()
{  
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600); 
}

void loop()
{         
  if (Serial.available() > 0)    
  {      
    int counter = Serial.parseInt();      
    for (int i = 0; i < counter; i++)      
      {          
        digitalWrite(ledPin, HIGH);          
        delay(500) ;          
        digitalWrite(ledPin, LOW);          
        delay(500) ;      
        Serial.print (counter) ;       
        Serial.print (" ") ;     
        Serial.print ( i) ;          
        Serial.println ("") ;      
      }        
   }
}

Thank you

dannydebont:
Thank you

No problem , I hope this solves your problem.