diff --git a/LM75.cpp b/LM75.cpp index f98564f..c091874 100644 --- a/LM75.cpp +++ b/LM75.cpp @@ -104,6 +104,10 @@ void LM75::thyst (float temp) { _register16(LM75_THYST_REGISTER, float2regdata(temp)); } +void LM75::setaddr (byte addr) { + address = addr; +} + boolean LM75::shutdown () { return conf() & 0x01; } diff --git a/LM75.h b/LM75.h index 5bd46ae..5d61552 100644 --- a/LM75.h +++ b/LM75.h @@ -56,6 +56,7 @@ class LM75 { void tos (float); float thyst (void); void thyst (float); + void setaddr (byte); void shutdown (boolean); boolean shutdown (void); }; diff --git a/examples/MultiUsage/MultiUsage.pde b/examples/MultiUsage/MultiUsage.pde new file mode 100644 index 0000000..ba5b616 --- /dev/null +++ b/examples/MultiUsage/MultiUsage.pde @@ -0,0 +1,76 @@ +/* + LM75 - An arduino library for the LM75 temperature sensor + Copyright (C) 2011 Dan Fekete + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include + +LM75 sensor; // initialize an LM75 object +// You can also initiate with another address as follows: +//LM75 sensor(LM75_ADDRESS | 0b001); // if A0->GND, A1->GND and A2->Vcc +byte sensaddr[2]={ + 0x49, // A0->GND, A1->GND and A2->GND + // 0x4B, // A0->Vcc, A1->Vcc and A2->Vcc + 0x4F // A0->Vcc, A1->Vcc and A2->Vcc +}; +float senshigh[2]={ + 27.5, + 22.5 +}; +float sensdown[2]={ + 25.0, + 20.0 +}; + +void setup() +{ + Wire.begin(); + Serial.begin(9600); + while (!Serial); // Leonardo: wait for serial monitor + Serial.println("\nMultiple LM75 I2C temperature sensor"); + for (int i = 0 ; i < sizeof(sensaddr) ; i++) { + Serial.println(sensaddr[i]); + // set address + sensor.setaddr(sensaddr[i]); + // Tos Set-point + sensor.tos(senshigh[i]); + Serial.print("Tos set at "); + Serial.print(sensor.tos()); + Serial.println(" C"); + + // Thyst Set-point + sensor.thyst(sensdown[i]); + Serial.print("Thyst set at "); + Serial.print(sensor.thyst()); + Serial.println(" C"); + } +} + +void loop() +{ + for (int i = 0 ; i < sizeof(sensaddr) ; i++) { + // set address + sensor.setaddr(sensaddr[i]); + // get temperature from sensor + Serial.print("Current temp "); + Serial.print(sensaddr[i]); + Serial.print(": "); + Serial.print(sensor.temp()); + Serial.println(" C"); + } + delay(3000); +}