-2

This is my code but it doesn't work. I don't no why . I hope someone can explain the problem. Tks

unsigned char InTransfer;
char buffer;
void setup()
    {
  Serial.begin(9600);
}

void loop()
{
  /* when get the sentences and print it*/
   while ( Serial.available())
  { 
    buffer=Serial.read();
    Serial.write(buffer);
    InTransfer=1;    // detect 
  }
  /* After done enter one time */
  if (Serial.available()==0)
    if(InTransfer==1){
      Serial.println("");
      InTransfer=0;
  }
}

closed as unclear what you're asking by Nick Gammon, TheDoctor, Anonymous Penguin Nov 5 '15 at 23:36

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Can you provide more information? What doesn't work? Does it compile? What is it meant to do? – Greenonline Oct 19 '15 at 15:55
1

Your code works perfectly, I don't see a problem with it. It's doing exactly what you're telling it to.

The problem lies in a fundamental lack of understanding about how serial communications work on your part, so you are telling it to do the wrong thing. Until you fix that aspect no program you try and write in this way will be a success.

You should start by learning how serial communication actually works. A good starting point is an article I wrote ages ago: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

  • Can u tell me how to fix this problem ? or give me an related example because I don't understand more. Thank you – giang phuc Oct 18 '15 at 15:56
  • @giangphuc Follow the link. Read the text. – Majenko Oct 18 '15 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.