Delay between two switches

Hi…

#include"Arduino.h"
#include <TimerOne.h>
float duty;
float T ;// in microsecond
void setup() 
{   
  T=100;
  Timer1.initialize(T); 
  
}
 
void loop(){
  // Main code loop

    duty=.4;
    Timer1.pwm(9,duty*1024); 
    //delayMicroseconds(40);
    Timer1.pwm(10,(1-duty)*1024);
}

How to give delay between two pins( ie. PIN 9 and PIN 10)?
I want both the PWM switches should be complementary (ie. if one switch is on then other should be off).

Just a try. Take one PWM, an toggle both pins at the interrupt.

Best way is with some external hardware then - a simple NOT gate. Can be a single transistor and couple of resistors even to invert the PWM signal.

Your method will produce different width pulses.

The other way is with direct port manilupation, writing 01 and 10 to two pins at the same time.

example: PORTB = 0b00000010; // D9 high, D10 low and PORTB = 0b00000100; // D10 high, D9 low

so perhaps:

void loop(){
currentMicros = micros();
elapsedMicros = currentMicros - nextMicros; // all time related elements are unsigned long
if ( elapsedMicros >= duration){
nextMicros = nextMicros + duration;
state = 1-state;  // define state as 0 to start, then result is 1-0 =1, 1-1 = 0, 
  if (state ==1){
  PORTB = 0b00000010; // D9  high, D10 low
  }
  else{
  PORTB = 0b00000100; // D10 high, D9 low
  }

} // end time check
//
// can do other stuff while waiting for time to pass
//
} // end loop
float T ;// in microsecond
void setup() 
{   
  T=100;
  Timer1.initialize(T);

Define a float. Initialize it with an int. Pass it to a function that expects an unsigned long. Why, why, and why?