1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature OneWireBus(&oneWire);
uint8_t ONBOARD_ADDRESS[] =
{
0x28, 0x4C, 0x0B, 0x0E, 0x0E, 0x00, 0x00, 0x87
};
uint8_t CHANNEL_2_ADDRESS[8] =
{
0x28, 0x95, 0x28, 0x49, 0xF6, 0xCD, 0x3C, 0x8D
};
class OneWireSensor
{
protected:
DeviceAddress m_OneWireAddress;
public:
OneWireSensor(uint8_t OneWireAddress[])
{
for (int i = 0; i < 8; i++)
{
m_OneWireAddress[i] = OneWireAddress[i];
}
}
float GetTemp()
{
return (OneWireBus.getTempC(m_OneWireAddress));
}
};
// create the instances
OneWireSensor OnboardSensor(ONBOARD_ADDRESS);
OneWireSensor Channel2Sensor(CHANNEL_2_ADDRESS);
void setup()
{
OneWireBus.begin(); // start the one wire sensor library
Serial.begin(115200);
}
void loop()
{
OneWireBus.requestTemperatures();
Serial.print("Onboard Temperature GetTemp: ");
Serial.println(OnboardSensor.GetTemp());
Serial.print("Channel2 Temperature GetTemp: ");
Serial.println(Channel2Sensor.GetTemp());
Serial.println();
// WITH THE SENSORS IN TWO VERY DIFFERENT TEMPERATURES,
// THE ABOVE TWO PRINTS SHOW THE CORRECT, and different, DATA
delay(500);
}
|