# Digital Input

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

<figure><img src="/files/zsQUhiokDeRq2wiYQy3B" alt=""><figcaption><p>3.3V and Gnd bus rails, a toggle switch on D4, and a momentary switch on D6.</p></figcaption></figure>
{% endtab %}

{% tab title="2" %}

<figure><img src="/files/cvGBaKSkSPH0uIqIRYYM" alt=""><figcaption><p>Blue bus rail connected to gnd with an orange jumper wire. Red bus rail connected to 3.3V with a yellow jumper wire.</p></figcaption></figure>
{% endtab %}

{% tab title="3" %}

<figure><img src="/files/vM6JstPPGbQXMFhzEk95" alt=""><figcaption><p>Center pin of toggle switch connected directly to D4. Normally-open momentary switch connects D6 to Gnd when pushed.</p></figcaption></figure>
{% endtab %}

{% tab title="4" %}

<figure><img src="/files/nco0ooNV4W1L9D7naYfC" alt=""><figcaption><p>Toggle switch in "On" possition, conecting D4 to 3.3V.</p></figcaption></figure>
{% endtab %}

{% tab title="5" %}

<figure><img src="/files/3gJYP93YcUmTfENVNcrN" alt=""><figcaption><p>Toggle switch in "Off" possition, conecting D4 to Gnd.</p></figcaption></figure>
{% endtab %}

{% tab title="6" %}

<figure><img src="/files/dDNQ1haTt6pHPk1VHMCg" alt=""><figcaption><p>Momentary switch unpushed, internal pull-up resistor connects D6 to 3.3V.</p></figcaption></figure>
{% endtab %}

{% tab title="7" %}

<figure><img src="/files/AIuoTyf937zwpB9vNKRQ" alt=""><figcaption><p>Momentary switch pusshed, pulls D6 down to Gnd.</p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Circuit Python Library

<https://docs.circuitpython.org/en/latest/shared-bindings/digitalio/index.html>

## Pull-Up Resistors

<https://en.wikipedia.org/wiki/Pull-up_resistor>

## Code

```python
"""
Digital Input Demo Code
Breadstick Innovations
April 22, 2024
https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/digital-input
"""

from board import *
from time import sleep
from digitalio import DigitalInOut, Direction, Pull
from adafruit_dotstar import DotStar

"""LED Setup"""
leds = DotStar(DOTSTAR_CLOCK, DOTSTAR_DATA, 24, brightness=0.02, auto_write=False)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
OFF = (0, 0, 0)
leds.fill(OFF)
leds.show()

"""Toggle Switch Setup"""
toggle_4 = DigitalInOut(D4)
toggle_4.switch_to_input()

"""Momentary Switch Setup"""
button_6 = DigitalInOut(D6)
button_6.switch_to_input(Pull.UP)

"""Loop"""
while True:
    if toggle_4.value == True:
        leds[0] = GREEN
    else:
        leds[0] = RED

    if button_6.value == True:
        leds[8] = GREEN
    else:
        leds[8] = RED
        
    leds.show()
    sleep(0.03)

```


---

# 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/digital-input.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.
