From 1dbd599d2c10c5d0e1f6392f80d240ae6ee531dc Mon Sep 17 00:00:00 2001 From: aurek Date: Wed, 1 Mar 2017 00:08:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=B0=20=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BD=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D0=BC=D0=B8=20=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=B0=D0=BC=D0=B8=20=D0=BD=D0=B0=20=D1=88?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5=20I2C.=20=D0=9F=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=B0=D1=82=D1=87=D0=B8=D0=BA=D0=B0=D0=BC=D0=B8.=20Metho?= =?UTF-8?q?d=20for=20changing=20the=20address=20of=20the=20sensor=20for=20?= =?UTF-8?q?multiple=20sensors=20on=20the=20I2C=20bus.=20An=20example=20of?= =?UTF-8?q?=20the=20multiple=20sensors.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LM75.cpp | 4 ++ LM75.h | 1 + examples/MultiUsage/MultiUsage.pde | 76 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 examples/MultiUsage/MultiUsage.pde 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); +}