trouble with simple IF...ELSE

I can't for the life of me work out why the code below doesn't work.
Never gets to the ELSE statement, something keeps changing the "pinstate" back to zero

Cheers
K

void BlinkLED13() 
{
  // blinks LED 13
  int pinstate;      // state of the output pin

  if (pinstate == 0) 
  {
    digitalWrite(ledPin, pinstate);
    pinstate = 1;  
    delay(100);
  } 
  else
  {
    digitalWrite(ledPin, pinstate);
    pinstate = 0; 
    delay(100);
  }

}

Make it static, or global. Actually it is erased when the function is exited, and recreated each time the function is called.

void BlinkLED13() 
{
  // blinks LED 13
  static int pinstate;

Sweet.
Thanks for that

Moving 'pinstate' outside of the 'BlinkLED13' function would do pretty much the same thing.

int pinstate;

void BlinkLED13()
{
    // blinks LED 13
    if ( pinstate == 0 ) 
    {
        digitalWrite(ledPin, pinstate);
        pinstate = 1;  
        delay(100);
    } 
    else
    {
        digitalWrite(ledPin, pinstate);
        pinstate = 0; 
        delay(100);
    }
}

When pins are set as OUTPUT 'digitalWrite' tracks the last value written to it which can then be read with 'digitalRead'. Combining this with the '!' not operator will allow your code to be simplified as -

void BlinkLED13()
{
    // blinks LED 13
    digitalWrite(ledPin, ! digitalWrite(ledPin));
    delay(100);
}

I do find your choice of the function name, 'BlinkLED13', to be somewhat misleading as it simply changes the LED to it's opposite state.

That concept of a 'blink' does not match mine.

This one I consider more a 'toggle' as it requires multiple explicit calls to the function in order to 'blink'.