#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).
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