Operator Symbol
Arduinoでプログラムを作るときに、演算子で条件などを表す必要がある。
数式とは異なる使い方をするので注意する。
【 = 】
=は、代入演算子(assignment operator)で、右側の値を左の変数に入れる。
Example
int sensVal; // declare an integer variable named sensVal
sensVal = analogRead(0); // store the (digitized) input voltage at analog pin 0 in SensVal
【 == != < > <= >= 】
if文などで使われる比較演算子。
==は数学でいう「=」のように等号として使う。
【 && || ! 】
if文などで使われる論理演算子。
&&はAND、||はOR、!はNOT
【 ++ -- 】
++は加算代入で変数に1を加える。 --は-1
後に++がつく場合は、1は加えるが、返すのは古い値になる。
Syntax
x++; // increment x by one and returns the old value of x ++x; // increment x by one and returns the new value of x
Examples
x = 2; y = ++x; // x now contains 3, y contains 3 y = x--; // x contains 2 again, y still contains 3
【 += -= *= /= %= &= |= 】
+=は元の変数に右の値を加える。
Examples
x = 2; x += 4; // x now contains 6 x -= 3; // x now contains 3 x *= 10; // x now contains 30 x /= 2; // x now contains 15 x %= 5; // x now contains 0