digitalWrite(x,!digitalRead(x))
بهترین و ساده ترین روش