46 lines
842 B
Text
46 lines
842 B
Text
|
|
#include <Wire.h>
|
||
|
|
//wire library
|
||
|
|
|
||
|
|
/*
|
||
|
|
Sourced from
|
||
|
|
http://www.instructables.com/id/Thermostat-Microcontroller-with-an-Arduino-and-a-T/step4/TC74-Arduino-code/
|
||
|
|
and modified a bit!
|
||
|
|
*/
|
||
|
|
|
||
|
|
//works better when you connect SDA and SCLK
|
||
|
|
|
||
|
|
#define address B1001101
|
||
|
|
#define baudrate 9600
|
||
|
|
//baudrate for communication
|
||
|
|
|
||
|
|
byte val = 0;
|
||
|
|
void setup()
|
||
|
|
{
|
||
|
|
Wire.begin();
|
||
|
|
Serial.begin(baudrate);
|
||
|
|
}
|
||
|
|
|
||
|
|
void loop()
|
||
|
|
{
|
||
|
|
Serial.print("temperature in Celsius: ");
|
||
|
|
//let's signal we're about to do something
|
||
|
|
|
||
|
|
int temperature;
|
||
|
|
//temperature in a byte
|
||
|
|
|
||
|
|
Wire.beginTransmission(address);
|
||
|
|
//start the transmission
|
||
|
|
|
||
|
|
Wire.write(val);
|
||
|
|
|
||
|
|
Wire.requestFrom(address, 1);
|
||
|
|
if (Wire.available()) {
|
||
|
|
temperature = Wire.read();
|
||
|
|
Serial.println(temperature);
|
||
|
|
}
|
||
|
|
|
||
|
|
else {
|
||
|
|
Serial.println("---");
|
||
|
|
}
|
||
|
|
delay(5000);
|
||
|
|
}
|