Hi Guys,
I'm really new to arduino and recently started some coding. I was wondering is there any way i can compare 2 Serial.Println?
Im working with a mq-7 Sensor and want to compare 2 values the mq-7 sensor gives back to me.
the end goal is: if 4 values after each other are the same then do something.
Thanks for the help!
ArduinoBot2000
Store the results that you get from your sensor in an array; don't print the results directly.
Next you can compare the array elements for the same value and act on that.
you got a link to a post on this forum explaining that some more?
system
4
Have you looked at any of the programming examples in the IDE?
wvmarle
5
One thing that will be of help is the Serial input basics post. That tells you how to read data from the serial input, and store it in a string.
After that you can check whether they're equal by doing a simple string comparison:
(edit: code correction)
if (strcmp(string1, string2) == 0) {
// Equal!
}
ArduinoBot2000:
you got a link to a post on this forum explaining that some more?
How about posting your current code so we can see what you're doing and tailor our advise.
//if (strcmp(string1, string2) == -1) {
if (strcmp(string1, string2) == 0) {
// Equal!
}
You're right... thanks for the correction, I was mixing up things again