Much simpler than the examples above, if you just want to toggle the output of a single pin you can do:
digitalWrite(ledPin, !digitalRead(ledPin));
Much simpler than the examples above, if you just want to toggle the output of a single pin you can do:
digitalWrite(ledPin, !digitalRead(ledPin));