1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
char tabCommande[10]="";
int i;
void setup() {
// initialize serial:
Serial.begin(9600);
inputString.reserve(10);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
//Affichge str
Serial.print("Nombre de caractere:"); Serial.println(inputString.length());
Serial.print("str : "); Serial.println(inputString);
//Affiche tableau
for(i=0; i<inputString.length(); i++)
{
Serial.print("case : "); Serial.println(tabCommande[i]);
tabCommande[i] = 0; //clear
}
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
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
// fin de caractere
if (inChar == '<') {
stringComplete = true;
//convert in array
inputString.toCharArray(tabCommande,inputString.length()+1);
}
}
} |
Partager