user26743: I am currently using arduino library to logically set my digital pins high or low, but I just realized how slowly it actually sets those pins, which is especially problem as i am doing this in a ISR routine. Can't this be done faster by actually acessing the direct port, and setting the current pin? 
How do I convert something like this 
  digitalWrite(11, !digitalRead(11));

To something faster?
I am using a Arduino UNO.. 

user84: The fastest way may be to use assembly from your C++ code:
asm volatile("SBI %[IOREG], %[BIT] \n\t"::[IOREG] "I" (&PINB), [BIT] "I" (PB3));

This forces a 1 to the bit for pin 11 (bit 3 on port B of the ATmega328), which, as per the Atmel datasheet, will simply toggle output (1 to 0 or 0 to 1) on that pin (provided it was initially setup as output).
As far as I remember the assemby instruction SBI used above cannot be generated by g++ (the C++ compiler used by Arduino IDE), hence you have to code it yourself.
You won't be able to achive a better performance as this single assembly instruction takes exactly 2 clock cycles to execute (ie 125 ns on an Arduino UNO).

user4215: Yes there is!
You can directly manipulate the port. The Arduino website has a pretty good explanation for it here.
Togelling a pin as asked by you can be simply done by something like this:
  PORTB ^= _BV(PINNUMBER)

A simplified way is the digitalWriteFast library.

This library consists of a complex header file that translates digitalWriteFast, pinModeFast, digitalReadFast into the corresponding PORT commands. It provides syntax that is as novice-friendly as the arduino's pin manipulation commands but an order of magnitude faster. 


user368: Since pin 11 on the ATmega328P is PB3:
PINB |= _BV(PB3);


user-1: Yes, it is possible
The atmel chip at the core of the arduinos can set or clear individual pin output levels in a single operation. There are special instructions to do so SBI and CBI- you just need to figure out what C compiles down to those instructions.
Each pin is represented by one bit of a port byte, for pin 11 it's bit 3 on port B.  So you can toggle it with 
PORTB ^= _BV(PB3);

or set it with
PORTB |= _BV(PB3);

or clear it with
PORTB &= ~_BV(PB3);

Probably the last two will compile to a single SBI/CBI instruction while the toggle one may or may not, depending on the code and how the compiler optimises it.

26743: <p>I am currently using arduino library to logically set my digital pins high or low, but I just realized how slowly it actually sets those pins, which is especially problem as i am doing this in a ISR routine. Can't this be done faster by actually acessing the direct port, and setting the current pin? </p>

<p>How do I convert something like this </p>

<pre><code>  digitalWrite(11, !digitalRead(11));
</code></pre>

<p>To something faster?</p>

<p>I am using a Arduino UNO.. </p>
 84: <p>The fastest way may be to use assembly from your C++ code:</p>

<pre><code>asm volatile("SBI %[IOREG], %[BIT] \n\t"::[IOREG] "I" (&amp;PINB), [BIT] "I" (PB3));
</code></pre>

<p>This forces a <code>1</code> to the bit for pin 11 (bit 3 on port B of the ATmega328), which, as per the Atmel datasheet, will simply toggle output (1 to 0 or 0 to 1) on that pin (provided it was initially setup as output).</p>

<p>As far as I remember the assemby instruction <code>SBI</code> used above cannot be generated by g++ (the C++ compiler used by Arduino IDE), hence you have to code it yourself.</p>

<p>You won't be able to achive a better performance as this single assembly instruction takes exactly 2 clock cycles to execute (ie <strong>125 ns</strong> on an Arduino UNO).</p>
 4215: <p>Yes there is!<br>
You can directly manipulate the port. The Arduino website has a pretty good explanation for it <a href="https://www.arduino.cc/en/Reference/PortManipulation" rel="nofollow">here.</a></p>

<p>Togelling a pin as asked by you can be simply done by something like this:</p>

<pre><code>  PORTB ^= _BV(PINNUMBER)
</code></pre>

<p>A simplified way is the <a href="https://code.google.com/archive/p/digitalwritefast/" rel="nofollow">digitalWriteFast</a> library.</p>

<blockquote>
  <p>This library consists of a complex header file that translates digitalWriteFast, pinModeFast, digitalReadFast into the corresponding PORT commands. It provides syntax that is as novice-friendly as the arduino's pin manipulation commands but an order of magnitude faster. </p>
</blockquote>
 368: <p>Since pin 11 on the ATmega328P is PB3:</p>

<pre><code>PINB |= _BV(PB3);
</code></pre>
 -1: <p><strong>Yes, it is possible</strong></p>

<p>The atmel chip at the core of the arduinos can set or clear individual pin output levels in a single operation. There are special instructions to do so <code>SBI</code> and <code>CBI</code>- you just need to figure out what C compiles down to those instructions.</p>

<p>Each pin is represented by one bit of a port byte, for pin 11 it's bit 3 on port B.  So you can toggle it with </p>

<pre><code>PORTB ^= _BV(PB3);
</code></pre>

<p>or set it with</p>

<pre><code>PORTB |= _BV(PB3);
</code></pre>

<p>or clear it with</p>

<pre><code>PORTB &amp;= ~_BV(PB3);
</code></pre>

<p>Probably the last two will compile to a single <code>SBI</code>/<code>CBI</code> instruction while the toggle one may or may not, depending on the code and how the compiler optimises it.</p>
