int pulse_width = 10000; //pulsewidth in micro seconds. i.e 10 ms i.e. 100Hz pwm
int duty_ratio = 10;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
}
void loop() {
int On_time = duty_ratio*(pulse_width/100);
int Off_time = pulse_width - On_time;
Serial.print(" on_time = ");
Serial.print(On_time);
Serial.print(" ");
Serial.print("off_time = ");
Serial.println(Off_time);
digitalWrite(12, HIGH); // led turn on
delayMicroseconds(On_time); //keep turn on for On_time
digitalWrite(12, HIGH); //led turn off
delayMicroseconds(Off_time); //keep turn off for Off_time
}