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
 9
10import board
11from adafruit_onewire.bus import OneWireBus
12
13import adafruit_ds2413
14
15# Create OneWire bus
16ow_bus = OneWireBus(board.D2)
17
18# Create the DS2413 object from the first one found on the bus
19ds = adafruit_ds2413.DS2413(ow_bus, ow_bus.scan()[0])
20
21# LED on IOA
22led = ds.IOA
23
24# button on IOB
25button = ds.IOB
26button.direction = adafruit_ds2413.INPUT
27
28# Loop forever
29while True:
30    # Check for button press
31    if button.value:
32        # Print a message.
33        print("Button pressed!")
34        # Toggle LED
35        led.value = not led.value
36        # A little debounce
37        time.sleep(0.25)