/*
** Raspberry Pi Pico SDK PWM Example
** Originally from Pico PMW Example, simplified
**  
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/pwm.h"

#define GPIO_LED 3
#define MAX_DUTY_CYCLE 100 // percent

int main() {
  int change = 10;    
  int dutyPercent = 0;
  float clkdiv = 255.0;

  stdio_init_all(); // UART setup for both input and output

  // PWM setup
  gpio_set_function(GPIO_LED, GPIO_FUNC_PWM);
  uint slice_num = pwm_gpio_to_slice_num(GPIO_LED);
  pwm_set_clkdiv(slice_num, clkdiv);
  pwm_set_wrap(slice_num, MAX_DUTY_CYCLE);  
  pwm_set_enabled(slice_num, true);

  while (1) {
    dutyPercent += change;
    if (dutyPercent >= MAX_DUTY_CYCLE) {
      dutyPercent = 0;
    } // when at max, go directly back to zero

    pwm_set_gpio_level(GPIO_LED, dutyPercent);
    printf("LED is now %d\r\n", dutyPercent);
    sleep_ms(200);

  }
}
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
bz1:1
bz1:2