# ADC

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

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

{% tab title="2" %}

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

{% tab title="3" %}

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

{% tab title="4" %}

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

{% tab title="5" %}

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

{% tab title="6" %}

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

{% tab title="7" %}

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

## ADC Pins - A1, A2, A18, A17

While all ADC pins are digital pins, not all digital pins are ADC pins.&#x20;

## Code

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

ADC converts 0-3.3V to 16-bit integer
RP2040 has a 12-bit ADC but CircuitPython converts it to a 16-bit result.
2^16 = 65536 values
0 is one of those values,
so the range is 0-65535.
3.3V/65535 steps = 50uV/step
You won't actually measure at 50uV accuracy, closer to 1mV accuracy.
"""

from board import *
from pwmio import PWMOut
from analogio import AnalogIn
from time import sleep
from adafruit_dotstar import DotStar


def convert_voltage(ADC_value):
    return 3.3 / 65535 * ADC_value


def convert_range(ADC_value, from_max, to_max):
    return int(ADC_value / from_max * to_max)
    

pot_1 = AnalogIn(A1)
pot_18 = AnalogIn(A18)

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

leds = DotStar(DOTSTAR_CLOCK, DOTSTAR_DATA, 24, brightness=0.02, auto_write=False)

RED = (255, 0, 0)
ORANGE = (255, 75, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
OFF = (0, 0, 0)

leds.fill(OFF)
leds.show()

while True:
    ADC_1 = pot_1.value
    ADC_18 = pot_18.value

    led_5.duty_cycle = ADC_1

    voltage_1 = convert_voltage(ADC_1)
    voltage_18 = convert_voltage(ADC_18)
    print((voltage_1, voltage_18))

    bar_graph = convert_range(ADC_18, 65535, 25)
    leds.fill(OFF)
    for i in range(bar_graph):
        leds[i] = ORANGE
    leds.show()

    sleep(0.04)

```


---

# 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/adc.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.
