Simple test

Ensure your device works with this simple test.

examples/ds2413_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# This example shows how to access the DS2413 pins and use them for both input
 5# and output. In this example, it is assumed an LED is attached to IOA and a
 6# button is attached to IOB. See the datasheet for details about how to
 7# interface the external hardware (it is different than most Arduino examples).
 8import time
 9import board
10from adafruit_onewire.bus import OneWireBus
11import adafruit_ds2413
12
13# Create OneWire bus
14ow_bus = OneWireBus(board.D2)
15
16# Create the DS2413 object from the first one found on the bus
17ds = adafruit_ds2413.DS2413(ow_bus, ow_bus.scan()[0])
18
19# LED on IOA
20led = ds.IOA
21
22# button on IOB
23button = ds.IOB
24button.direction = adafruit_ds2413.INPUT
25
26# Loop forever
27while True:
28    # Check for button press
29    if button.value:
30        # Print a message.
31        print("Button pressed!")
32        # Toggle LED
33        led.value = not led.value
34        # A little debounce
35        time.sleep(0.25)