How to effectively use the Not equal to operator in Arduino
2 min. read
Updated on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
Key notes
- Arduino is based on the C/C++ programming language; most of the functions of C++ are available, plus some specific extensions.
- The not equal to relational operator is one of the common language structure elements in Arduino and we'll see how it's used.
- For more specific articles, make sure to take a look at our dedicatedย Arduino Hub.
- Also, go to ourย Developer Toolsย section for more insightful information.
Single-board microcontroller Arduino uses C/C++ programming language, which comprises sets of functions, values (variables and constants), and language structure elements.
Theย not equal to a structure is part of the comparison operators, alongside equal to,ย less than, less than or equal to, greater than, greater than or equal to. The graphic sign is !=.
How do I use not equal to with Arduino?
Not equal to is an element that compares one variable on the left with a value or variable on the right of the operator.
It returns true when the two operands are not equal.
The syntax is usually the following:
x != y; // is false if x is equal to y and it is true if x is not equal to y
What not equal to condition does is to say that if the current state doesn’t equal the previous state, then do this.
In the above example, you make a call for all values of x that areย not equal to 2 to be printed in the Serial Monitor, with a delay of 500ms, to allow you to click the button.
It’s recommended to compare variables of the same data type including the signed/unsigned type. Comparing variables of different data types is possible, but it could generate unpredictable results.
The Serial Monitor is not working on your Arduino? Try these solutions.
Note that the Arduino IDE uses C++, but since the physical environment is limited,ย not all C/C++ features can be used and the Arduino environment. As a result, Arduino has helper functions (specific extensions) to enable you to use the hardware easily.
[wl_navigator]
User forum
0 messages