diff --git a/OneWire.cpp b/OneWire.cpp index 81d1a92..ca330fc 100644 --- a/OneWire.cpp +++ b/OneWire.cpp @@ -1,6 +1,12 @@ /* Copyright (c) 2007, Jim Studt (original old version - many contributors since) +Modifications by Prashant : An extra no arguments constructor to simplify +multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, +in the limited environment provided by Arduino. +See the Multibus_simple example illustrating a use-case of the extension. +Use in conjunction with my modification of the DallasTemperature library. + Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state. @@ -122,7 +128,8 @@ sample code bearing this copyright. #include "OneWire.h" -OneWire::OneWire(uint8_t pin) +OneWire::OneWire() {} +void OneWire::setPin(uint8_t pin) { pinMode(pin, INPUT); bitmask = PIN_TO_BITMASK(pin); @@ -132,6 +139,11 @@ OneWire::OneWire(uint8_t pin) #endif } +OneWire::OneWire(uint8_t pin) +{ + setPin(pin); +} + // Perform the onewire reset function. We will wait up to 250uS for // the bus to come high, if it doesn't then it is broken or shorted diff --git a/OneWire.h b/OneWire.h index 7acd488..ace3255 100644 --- a/OneWire.h +++ b/OneWire.h @@ -126,6 +126,8 @@ class OneWire #endif public: + OneWire(); + void setPin(uint8_t pin); OneWire( uint8_t pin); // Perform a 1-Wire reset cycle. Returns 1 if a device responds diff --git a/README.md b/README.md index a0f9c8c..c9e877a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ Copyright (c) 2007, Jim Studt (original old version - many contributors since) +Modifications by Prashant : An extra no arguments constructor to simplify +multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, +in the limited environment provided by Arduino. +See the Multibus_simple example illustrating a use-case of the extension. +Use in conjunction with my modification of the DallasTemperature library. + Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state. diff --git a/examples/Multibus_simple/Multibus_simple.ino b/examples/Multibus_simple/Multibus_simple.ino new file mode 100644 index 0000000..a818e07 --- /dev/null +++ b/examples/Multibus_simple/Multibus_simple.ino @@ -0,0 +1,48 @@ +#include +#include + +int oneWirePins[]={3,7};//OneWire DS18x20 temperature sensors on these wires +const int oneWirePinsCount=sizeof(oneWirePins)/sizeof(int); + +OneWire ds18x20[oneWirePinsCount]; +DallasTemperature sensor[oneWirePinsCount]; + + +void setup(void) { + // start serial port + Serial.begin(9600); + Serial.println("Dallas Temperature Multiple Bus Control Library Simple Demo"); + Serial.print("============Ready with "); + Serial.print(oneWirePinsCount); + Serial.println(" Sensors================"); + + // Start up the library on all defined bus-wires + DeviceAddress deviceAddress; + for (int i=0; i