-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS1624.cpp
More file actions
47 lines (39 loc) · 1.07 KB
/
DS1624.cpp
File metadata and controls
47 lines (39 loc) · 1.07 KB
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
/*
Library for controlling the DS1624 ic with Arduino
Tested with arduino-0018
26/03/2010 Release 0.1
Written by Federico and Riccardo Galli
http://www.sideralis.org
fixed by Richard Toth http://risko.org
*/
#include "DS1624.h"
#include <Wire.h>
#include <Arduino.h>
DS1624::DS1624(int8_t addr)
{
this->addr=addr;
Wire.begin();
}
void DS1624::start()
{
Wire.beginTransmission(this->addr);
Wire.write(0xAC);
Wire.write(CONTINUOUS_CONVERSION); //Put the DS1624 in continuos conversion mode
Wire.endTransmission();
delay (100); //Min time needed to store the previous command is 10ms
Wire.beginTransmission(this->addr);
Wire.write(CONVERT_T); //Enable the continuos conversion mode
Wire.endTransmission();
}
float DS1624::getTemp()
{
uint16_t t = 0;
Wire.beginTransmission(this->addr);
Wire.write(READ_T);
Wire.requestFrom(this->addr, 2);
if (Wire.available()) t = Wire.read() << 8;
if (Wire.available()) t |= Wire.read();
Wire.endTransmission();
t >>= 4;
return (float)((t & 0x800 ? (t & 0x7ff) - 0x800 : t) / 16.0);
}