Read state of digital pin and toggle it if possible?

I do have a arduino uno and a relay,

currently i change its state with:

void setup(){
 pinMode(13,         OUTPUT);
}

..........
delay(200);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
...............

is there a way i can "read" the previous state of PIN13 on my uno and just flip it to the other state?

digitalRead(13, STATE);
digitalWrite(13,!STATE);

It is just Digital PIN13 which i use for an relay (SSR) and it would be nice to change it state with one command..

Thank you very much everyone!

Although it sounds odd you can use digitalRead() on a pin whose more is OUTPUT so you can do

digitalWrite(pinNum, !digitalRead(pinNum));

Flip the state of an output pin on AVR-based Arduinos in one line of code by using another “odd” command.

For pin 13 on an Arduino Uno (PORTB, bit 5), this is

PINB = (1<<5);  //invert output bit 5

Thank you!

Will Test it as fast as i come home and can programm again.. should work with the avr command as well!

That’s why I almost always have:

bool digitalToggle(byte pin){
  bool state = !digitalRead(pin);
  digitalWrite(pin, state);
  return state;
}