-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLM74.cpp
More file actions
59 lines (47 loc) · 1.17 KB
/
LM74.cpp
File metadata and controls
59 lines (47 loc) · 1.17 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
48
49
50
51
52
53
54
55
56
57
58
59
/*
LM74.cpp - Arduino library support for the LM74 SPI Bus
Author: Abraxas666
This library has been made to easily interface and use the LM74 with the Arduino
This library makes use of the built-in hardware SPI port of the microcontroller
so there are some pin connections that are required, see the board documentation
*/
#include "LM74.h"
#include <SPI.h>
LM74::LM74(int ss_pin )
{
CS = ss_pin ;
}
void LM74::begin()
{
digitalWrite(CS, HIGH);
pinMode(CS, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
SPISettings settings(16000000, MSBFIRST, SPI_MODE3);
}
float LM74::read ()
{
SPI.begin();
digitalWrite (CS, LOW);
byte1 = SPI.transfer(0);
byte2 = SPI.transfer(0);
digitalWrite (CS, HIGH);
regbits = (byte1 << 8) + byte2;
regbits = (regbits >>3 );
temp = regbits * 0.0625;
return temp;
}
float LM74::readf ()
{
SPI.begin();
digitalWrite (CS, LOW);
byte1 = SPI.transfer(0);
byte2 = SPI.transfer(0);
digitalWrite (CS, HIGH);
regbits = (byte1 << 8) + byte2;
regbits = (regbits >>3 );
temp = regbits * 0.0625;
temp = 1.8 * temp + 32 ;
return temp;
}