Lecture port série

Fonction pour détecter l’arrivée d’un caractère sur le port série :

 void serialEvent() {  
  inputString = "";  
  while (Serial.available()) {  
   // get the new byte:  
   char inChar = (char)Serial.read();  
   // add it to the inputString:  
   inputString += inChar;  
   // if the incoming character is a newline, set a flag  
   // so the main loop can do something about it:  
   if (inChar == '\n') {  
    stringComplete = true;  
   }  
  }  
 }  

Mise en oeuvre dans la fonction loop() :

 void loop()  
 { if (stringComplete)  
   stringComplete = false;  
  delay(100);  
  //-- Traitement  de la chaine récupéree inputString 
 }  

Avec la carte Mega vous pouvez utiliser les 3 ports série :

void serialEvent1() ou void serialEvent2() ou void serialEvent3()

Code complet dans l’exemple serialEvent

 

Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories