Arduino 1-Wire Device Libraries

DS2423 Example Code

This example demonstrates the use of the library to continuously read both DS2423 counters and print the values to the serial port.

// Copyright 2013, bechter.com - All Rights Reserved
#include <Arduino.h>
#include <OneWire.h>
#include <DS2423.h>

// define the Arduino digital I/O pin to be used for the 1-Wire network here
const uint8_t ONE_WIRE_PIN = 2;

// define the 1-Wire address of the DS2423 counter here
uint8_t DS2423_address[] = { 0x1D, 0x79, 0x31, 0x09, 0x01, 0x11, 0x00, 0x33 };

OneWire ow(ONE_WIRE_PIN);
DS2423 ds2423(&ow, DS2423_address);

void setup() {
    Serial.begin(9600);
    ds2423.begin(DS2423_COUNTER_A|DS2423_COUNTER_B);
}

void loop() {
    ds2423.update();
    if (ds2423.isError()) {
        Serial.println("Error reading counter");
    } else {
        Serial.print("Count A = ");
        Serial.print(ds2423.getCount(DS2423_COUNTER_A));
        Serial.print(", Count B = ");
        Serial.println(ds2423.getCount(DS2423_COUNTER_B));
    }
    delay(500);
}

<<Previous Page | Index | Next Page>>