# PWM

{% tabs %}
{% tab title="1" %}

<figure><img src="/files/zp4MuPatlTJYWjmVor7x" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="2" %}

<figure><img src="/files/i7x2iKxIjnEQobz1hAVq" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="3" %}

<figure><img src="/files/73f8JSUWqdAvjTjYQVh6" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="4" %}

<figure><img src="/files/WxX4jKJjYJ4e9QrHpUMD" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="5" %}

<figure><img src="/files/73f8JSUWqdAvjTjYQVh6" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="6" %}

<figure><img src="/files/i7x2iKxIjnEQobz1hAVq" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="7" %}

<figure><img src="/files/zp4MuPatlTJYWjmVor7x" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Code

```python
"""
PWM Demo Code
Breadstick Innovations
April 26, 2024
https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/pwm

duty_cycle is a 16-bit integer
2^16 = 65536 values
0 is one of those values,
so the range is 0-65535.

range(start,stop,step)
range(0,10,1) = 0,1,2,3,4,5,6,7,8,9
range(10,0,-1) = 10,9,8,7,6,5,4,3,2,1
"""

from board import *
from pwmio import PWMOut
from time import sleep

led_5 = PWMOut(D5, frequency=500, duty_cycle=0)

while True:
    for i in range(0,65535,100):
        led_5.duty_cycle = i
        sleep(0.001)
    for i in range(65535,0,-100):
        led_5.duty_cycle = i
        sleep(0.001)
```


---

# Agent Instructions: 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:

```
GET https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/pwm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
