Help with configured pulse train output

As a beginner, I would like to write a simple code to toggle digital output on two Arduino DUO pins (#5 and 6 in this case). What I want to output should be something like

  • Each cycle is 10ms
  • In each even number cycle, pin 5 is set ON while pin 6 is set OFF, for only 3ms. After that both are set to OFF
  • In each odd number cycle, pin 6 is set ON while pin 5 is set OFF, for only 3ms. After that both are set to OFF

Running with the attached code, however, I could see something like a sine wave output from both pins with logic analyzer, as seen on the attached snapshot. And the frequency is way to high.

I would like to hear how to fix that piece of code.

Thanks.

Test_Pin_Output.ino (2.88 KB)

stevensung:
As a beginner, I would like to write a simple code

You seem to have chosen some very complex code.

Why not just use millis() or micros() for the timing as illustrated in Several Things at a Time. The examples use millis() but the same technique works with micros() if you need more precision.

...R