Let's Make Robots!

The fastest way to change or flip Arduino pins.

changes pins, very fast

I tested the difference in speed between the Arduino digitalWrite() function, and other methods of direct port manipulation. The results are surprising, check it out on my website. 

http://www.billporter.info/?p=308

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks! Very helpful.

Got a question: "Next I tested just flipping a pin. By this I mean I just changed the pin state without knowing what the initial state was without testing. The methods of testing" 

now this i what you wrote in you walkthrough and if i got it right you mean toggling (if 1, becomes 0 and if 0 becomes 1). But, if this is the case i don't understand this macro: #define sbi(port,bit) (port)|=(1<<(bit)) 

Basically what i don't understand is the |=, if i well remember that should be "compund" or but then if the bit 1 and you OR it with a 1 it'll still be 1, won't it? I have seen a similar setup but with XOR instead of OR. Most probably i'm the wrong one, but i can't understand why :=).

 

EDIT: did some googling and it looks like the secret lies in using PINB instead of PORTB ....wow, didn't know that :=) Double thanks for sharing then, i just learned a new trick!

its C not ASM.... what did you expected from a developing board? :) PICAXE is slow to in comparation with PIC :P

What may come as obvious to you and I may not be obvious to all; which is why I wrote the article. Even Arduino says it is slow, but not by how much.  

yes thats true... :) after all, now we can see how slow is this...