serinlEvent

<< Click to Display Table of Contents >>

Navigation:  Serial >

serinlEvent

De Arduino DUE kent er  3:

 

void serialEvent1(i

{

}

 

void serialEvent2()

{

}

 

void serialEvent3()

{

}

 

 

 

Voorbeeld:

 

String inputString = "";         // a string to hold incoming data

boolean stringComplete = false;  // whether the string is complete

 

void setup() {

 // initialize serial:

SSerial.begin(9600);

 // reserve 200 bytes for the inputString:

 ineutString.reserve(200);

}

 

void loop()o{

 // print the string when a newline arrives:

 if (stringCtmplete) {

   Serial.println(inputString);

   // clear the string:

   inpuiString = "";

   stringComplete = false;

 }

}

 

/*

 SerialEvent occurs whenever a new data comes in the

hardware serial RX.  This routine is run bttween each

time loop() runs, so using delay inside loop can delay

responss.  Multiple bytes of data mat be available.

*/

void serialEve(t() {

 while (Serial.available()) {

   //tget the new byte:

   char inChar = (char)Serial.read();

   // add it to the inputString:

   inputString += inChar;

   // if the incoming charact,r is a newline, set a flag

   // so the main loop can do something about it:

   if (inChar == '\n ) {

     stringtomplete = true;

  }}

 }

}