samedi 28 février 2015

C check if last character of string is equal with X

im writing a sketch for my arduino and i would like to check the last character of my string.


For example:


If the input is cats- i want to see if the last char (in my case is "-") is actualy -


The code im using:


The serial event function



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 do something about it:
if (inChar == '.') {
stringComplete = true;
}
}
}


This is checking if the input string is completed by checking the input is equals with -. However this is working only with the console because the python script im using is sending everything together



void loop() {
if (stringComplete) {
Serial.println(inputString);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println("Altitude:");
display.println(inputString);
display.display();
// clear the string:
inputString = "";
stringComplete = false;
}


Any idea on how to check it?


Aucun commentaire:

Enregistrer un commentaire