uint32_t pwmPin = 9; // use Digital pin D9 int cycle = 9; // Divide output into 9+1 = 10 portions int sourceClock = PWM_SOURCE_CLOCK_13MHZ; // int divider = PWM_CLOCK_DIV8; // The PWM frequency will be 13MHz / 8 / 10 = 162.5KHz int duty = 0; int offset = 1; void setup() { pinMode(pwmPin, OUTPUT); } void loop() { analogWriteAdvance(pwmPin, sourceClock, divider, cycle, duty); duty += offset; if (duty == cycle) { offset = -1; } else if(duty == 0) { offset = 1; } delay(1000); }