What do you mean by atomic?
If you arduino's pin operation functions, they are pin-oriented, meaning that they operate on one pin at a time. Say that you are outputing 0b0111 on the four pins and you want to go to 0b1000 next. As you can only write one pin at a time, you may set the msb first, making the output to be 0b1111, and then clear the lowest three pins, outputing 0b1011, then 0b1001 and then 0b1000.
The right approach is to work on the port so that all the state changes on the pins take place at the same time.
OK. I have never used a microcontroller until recently so I was keeping it simple using a sketch I found that outputs on digital pins 2,3,4,5 and uses delayMicroseconds to se the frequency.
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}
void loop()
{
for(int i=0;i<14;i++) // increment automatically
{
int a=i%2; // calculate LSB
int b=i/2 %2;
int c=i/4 %2;
int d=i/8 %2;
digitalWrite(5,d); //write MSB
digitalWrite(4,c);
digitalWrite(3,b);
digitalWrite(2,a); // write LSB
delayMicroseconds(100); // wait for x us
}
}