arduino pwm write code example
Example 1: arduino code analogwrite
analogWrite(Pin number here,0 - 255 value here);
Example 2: 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(){}