> For the complete documentation index, see [llms.txt](https://learn.breadstick.ca/breadstick/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.breadstick.ca/breadstick/pico-slices/slice-1-led-mixer/circuitpython-code/4-pot-controlled-pwm.md).

# 4 - Pot Controlled PWM

### Video

{% embed url="<https://youtu.be/V-sHN9kBXNQ>" %}

### Code with Detailed Comments

```python
"""
Pico Slice 1 - RGB Mixer
Tutorial 4 - Pot Controlled PWM
"""

import time
import board
from pwmio import PWMOut
from analogio import AnalogIn


# Represent the Pot in code as an AnalogIn object.
r_pot = AnalogIn(board.A2)

# Represent the Red LED as a PWMOut object.
r_led = PWMOut(board.GP2, duty_cycle=0, frequency=5000, variable_frequency=False)


while True:  # Loop Forever:
    input_val = r_pot.value         # Read the potentiometer's current value (16-bit)
    r_led.duty_cycle = input_val    # Set the red LED's duty-cycle (16-bit) to the current potentiometer value
    print((input_val,))             # Send to computer as a tuple so it will show up in the plotter
    time.sleep(0.1)                 # Do nothing for 100 milliseconds

```

### Just Code

```python
"""
Pico Slice 1 - RGB Mixer
Tutorial 4 - Pot Controlled PWM
"""

import time
import board
from pwmio import PWMOut
from analogio import AnalogIn

r_pot = AnalogIn(board.A2)
r_led = PWMOut(board.GP2, duty_cycle=0, frequency=5000, variable_frequency=False)

while True:
    input_val = r_pot.value
    r_led.duty_cycle = input_val
    print((input_val,))
    time.sleep(0.1)

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learn.breadstick.ca/breadstick/pico-slices/slice-1-led-mixer/circuitpython-code/4-pot-controlled-pwm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
