🍞
Breadstick
  • Breadstick Innovations Website
  • Breadsticks
    • đŸĨ–Raspberry Breadstick
      • Code Examples
        • Demo Code
        • POV Wand
        • Pride Flags POV Wand
        • 6-Axis IMU
        • RGB Blink
        • AsyncIO RGB Blink
        • Digital Input
        • Digital Output
        • PWM
        • ADC
        • Servo Motor
    • đŸĨ–Raspberry Breadstick Lite
    • 🍞Support Boards
      • I2C Devices
        • 🚌I2C Bus Rail Adapter
        • đŸŒĻī¸Weather Crouton
        • 😎Brightness Crouton
        • 📏Distance Crouton
        • đŸĢ¨Motion Crouton
      • I2S Devices
        • đŸ“ĸBoombox
      • SPI Devices
      • đŸ•šī¸Buttons/Switches
    • Learning Resources
    • Troubleshooting
  • Nougat
    • Nougat C3
    • Nougat Quad
    • Installing WLED
  • Pico Slices
    • 🔴Slice 1 - LED Mixer
      • Assembly Guide
      • CircuitPython Code
        • 1 - Blink
        • 2 - Analog Read to Plotter
        • 3 - PWM Fade
        • 4 - Pot Controlled PWM
        • 5 - Gamma Correction
    • âąī¸Slice 2 - Stopwatch
      • Assembly Guide
      • Coding Lessons
        • 1 - 7-Segment Display Intro
        • 2 - Cycling Through All Segments
    • âŦœSlice 3 - 8x8 Dot Matrix
      • Assembly Guide
      • MicroPython Code
        • 1 - Moveable Pixel
        • 2 - Snake
    • Circuit Python Setup
    • Reset Bricked Pico
  • Christmas
    • Christmas Tree DIY kit
  • Protoboards
    • â¤ī¸Proto-Heart
    • đŸĨĒProto-Toast
  • SHOP
Powered by GitBook
On this page
  • Circuit Python Library
  • Pull-Up Resistors
  • Code

Was this helpful?

  1. Breadsticks
  2. Raspberry Breadstick
  3. Code Examples

Digital Input

PreviousAsyncIO RGB BlinkNextDigital Output

Last updated 1 year ago

Was this helpful?

Circuit Python Library

Pull-Up Resistors

Code

"""
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)

đŸĨ–
https://en.wikipedia.org/wiki/Pull-up_resistor
https://docs.circuitpython.org/en/latest/shared-bindings/digitalio/index.html
3.3V and Gnd bus rails, a toggle switch on D4, and a momentary switch on D6.
Blue bus rail connected to gnd with an orange jumper wire. Red bus rail connected to 3.3V with a yellow jumper wire.
Center pin of toggle switch connected directly to D4. Normally-open momentary switch connects D6 to Gnd when pushed.
Toggle switch in "On" possition, conecting D4 to 3.3V.
Toggle switch in "Off" possition, conecting D4 to Gnd.
Momentary switch unpushed, internal pull-up resistor connects D6 to 3.3V.
Momentary switch pusshed, pulls D6 down to Gnd.