loop problem in serial communication


hi....
i want write code asks user input value either "john" or "mike"... if user enter "john" port send "led on" , turn "on" led on pin 13 , when use enter "mike" port send "led off" , turn "off" led , whole process starts again.
but problem when run code asks 1 time , when enter "john" turn led "on" don't start process again... 

here code




code: [select]

int ledpin = 13;
string content = "";
char character;


void setup()
{
  //create serial object
  serial.begin(9600);
  pinmode(ledpin, output);
}


void loop()
{
  if (serial.available())
  {
 
    character = serial.read();
    content.concat(character);
   
    if (content == "john")
    {
     serial.println("led on");
     digitalwrite(ledpin, high);
    }
    else if (content == "mike")
    {
      serial.println("led off");
      digitalwrite(ledpin, low);
    }
  }
}

you don't reset string, you're "adding" it.


Arduino Forum > Using Arduino > Programming Questions > loop problem in serial communication


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

Rasperry Wifi LAN Controller - Raspberry Pi Forums

Unlock car with bluetooth and car key