-
Notifications
You must be signed in to change notification settings - Fork 6
/
MCP342x.h
97 lines (75 loc) · 1.84 KB
/
MCP342x.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* MCP342x library version 1.9.4
Writed by B@tto
Contact : [email protected]
MCP342x.h - ADC 18 bits i2c library for Wiring & Arduino
Copyright (c) 2012 Yann LEFEBVRE. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MCP342x_H
#define MCP342x_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h>
//#include <Math.h>
enum MEASURE_MODE
{
ONE_SHOT_MODE=0,
CONTINUOUS_MODE
};
enum RESOLUTION
{
RESOLUTION_12_BITS=0,
RESOLUTION_14_BITS,
RESOLUTION_16_BITS,
RESOLUTION_18_BITS
};
enum CHANNELS
{
CH1=0,
CH2,
CH3,
CH4
};
enum PGA
{
PGA_X1=0,
PGA_X2,
PGA_X4,
PGA_X8
};
const uint8_t resolutionConvert[] = {12,14,16,18};
const uint8_t PGAConvert[] = {1,2,4,8};
class MCP342x {
public:
MCP342x(uint8_t adresse);
~MCP342x();
void begin(uint8_t setMod = 1);
void setConfiguration(byte channel,int resolution,int mode,int pga);
void newConversion();
bool isConversionFinished();
int32_t measure();
void getRawDatas(uint8_t buffer[4]);
uint8_t getConfiguration();
uint8_t getAddress();
private:
uint8_t _adresse;
int _resolution;
int _mode;
int _PGA;
int32_t _LSB;
uint8_t _buffer[4];
};
#endif