Assignment in code = !var

Hello, another question about c++

I inherited this code and I was curious what the meBlink = !meBlink; does, I'm assuming that whatever state mBlink was in previously it inverts it? Equivalent to a hardware inverter. I can not find anywhere in the code where mblink is actually set to 0 or 1 other than before setup.

This code works fine, I just want make sure I understand the function of meBlink = !meBlink;

const int LED = 13; //blink for doFreeRun()
int mBlink = 0; //meblink for LED
setup()
{
setup stuff
}
void loop()
{
do a bunch of stuff
runme();
}

runme()
{
     if (meBlink == 1){
          digitalWrite(LED, HIGH);
      }else{
          digitalWrite(LED, LOW);
      }
      
      meBlink = !mBlink;
}

That says if meblink is non-zero, make it zero. And if it is zero, make it 1.

It is the Boolean NOT operator.

! is a 'not' operator - it returns 0 (false) if the operand evaluates to true, and 1 (true) if the operand evaluates to false.

So that does indeed serve the purpose of toggling meBlink between 0 and 1.

The operators are listed on the reference page.

http://www.arduino.cc/en/Reference/HomePage

This is probably a typo: int mBlink = 0; //meblink for LED

Should be: byte meBlink = 0; //meblink for LED and meBlink = !meBlink;

Can also do this meBlink = 1 - meBlink; // 1-0 = 1, 1-1 = 0, 1-0 = 1, 1-1=0, ...

Then the whole if/else just becomes runme(){ digitalWrite (LED, meBlink); meBlink = 1 - meBlink; // invert for next use }

Yes it was a typo...sorry my bad and thanks, I like the additional short cut ;-)

CrossRoads: This is probably a typo: int mBlink = 0; //meblink for LED

Should be: byte meBlink = 0; //meblink for LED and meBlink = !meBlink;

Can also do this meBlink = 1 - meBlink; // 1-0 = 1, 1-1 = 0, 1-0 = 1, 1-1=0, ...

Then the whole if/else just becomes runme(){ digitalWrite (LED, meBlink); meBlink = 1 - meBlink; // invert for next use }

CrossRoads: This is probably a typo: int mBlink = 0; //meblink for LED

Should be: byte meBlink = 0; //meblink for LED and meBlink = !meBlink;

Can also do this meBlink = 1 - meBlink; // 1-0 = 1, 1-1 = 0, 1-0 = 1, 1-1=0, ...

Then the whole if/else just becomes runme(){ digitalWrite (LED, meBlink); meBlink = 1 - meBlink; // invert for next use }