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);
}
}
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 -