I'm pretty new to Arduino but I am familiar with other coding languages like Matlab.
Can anyone provide an example of using if statements?
Like I'm using a sensor to measure temperature and display it on a tft screen. I've included a short code below of how I think it would be formatted but looking for some guidance if that is how it's done.
In addition, I also want to average the readings over 10 seconds. Is that possible? I do not have an SD card or such to store measurements though.
Edit:
I know the syntax above is wrong. That was not my question. It is not suppose to represent any correct code. Just an example of what sort of thing I was looking for cause English is not my first language and I describe well with examples.
My question has already been answered and it was regarding where to find information about if statements. Thanks.
@ezrax123 - you need to start reading code, and coming to grips with the fact that spelling and punctuation and grammar and syntax count. And unlike Mrs. Smith, the compiler will spend no time trying to figure out what you might have meant when you stray.
You never ever saw an if in any functioning code that began like this:
How do you want to communicate correctly and completely with the compiler?
The compiler expects the syntax and rules required to write a programme for the Arduino to be adhered to.
Exactly why I did not write it as a code but an example code of what I was looking for and my best way of quickly describing it. Either way, I respect your opinion. Just not helpful for me. Thanks.
This can still be improved because there are unnecessary function calls in both statement blocks. (Statement blocks should be started with '{' and closed with '}'.) They are marked with a Dupe comment. I would change the code to this form:
This form clearly shows that the intent of the if-else statement block code is to change the text color on the display. It is much easier to read, uses less memory, and would execute marginally faster.
I forgot to mention one more potential problem. What if the temperature measures exactly 10. The first if statement block won't execute because it's False. In your original code, you then tested to see if the temperature was greater than 10. That, too, is False so in the original code the text color would not be set. In my code, the first expression is False, so the (default?) text color becomes RED since the first expression is False. That may or may not be what you want when the temperature is exactly 10. If that's the "desired" temperature, I'd make that text color GREEN. If the temp is too high, I'd set the color to RED (i.e.., too hot) and if the temp is too low, I'd make the color BLUE (i.e., too cold). Use the colors to convey information at a glance.
If you're interested in learning C in the Arduino IDE environment, I'd suggest Beginning C for Arduino (Amazon 1484209419). Read the reviews and see if this might be helpful. Disclaimer: I'm the author.
I do have multiple variables and I noticed that my code runs fine if the variable does not have a number. In other words, when I tried "int textColor_5", my screen did not display anything but when I changed it to "int textColor_a", it worked.
So I'm guessing that the variable set up cannot be numerical.
I'm not very familiar with C (at all, actually), thanks for the recommendation though! I will definitely check it out if I dabble more in software side of things.