Answers for "arduino custom pwm"

-1

arduino custom pwm

int DUTY = 50; // Duty percentage

const int PWM_PIN = 8;
 
void setup()
{
  pinMode(PWM_PIN, OUTPUT);
  noInterrupts();
 
  // Don't use loop() to avoid serialEventRun overhead
  while (true) {
    digitalWrite(PWM_PIN, HIGH);
    delayMicroseconds(DUTY); // Duty set above
    digitalWrite(PWM_PIN, LOW);
    delayMicroseconds(100 - DUTY); // Calculates downtime
  }
}
 
void loop(){}
Posted by: Guest on May-16-2020

Browse Popular Code Answers by Language