-
Notifications
You must be signed in to change notification settings - Fork 14
/
Adafruit_MCP3008.h
51 lines (46 loc) · 1.62 KB
/
Adafruit_MCP3008.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
/*!
* @file Adafruit_MCP3008.h
*
* This is a library for the MCP3008 - 8-Channel 10-Bit ADC with SPI Interface.
*
* Designed specifically to work with the Adafruit MCP3008.
*
* Pick one up today in the adafruit shop!
* ------> https://www.adafruit.com/product/856
*
* These breakout use SPI to communicate, 4 ping are required.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit andopen-source hardware by purchasing products
* from Adafruit!
*
* MIT license, all text above must be included in any redistribution
*/
#ifndef Adafruit_MCP3008_h
#define Adafruit_MCP3008_h
#include <Adafruit_SPIDevice.h>
#include <Arduino.h>
#define MCP3008_SPI_MAX_5V 3600000 ///< SPI MAX Value on 5V pin
#define MCP3008_SPI_MAX_3V 1350000 ///< SPI MAX Value on 3V pin
#define MCP3008_SPI_MAX MCP3008_SPI_MAX_3V ///< SPI MAX Value
#define MCP3008_SPI_ORDER SPI_BITORDER_MSBFIRST ///< SPI bit order
#define MCP3008_SPI_MODE SPI_MODE0 ///< SPI mode
#define MCP3008_SPI_FREQ 1000000 ///< SPI clock speed
/*!
* @brief Class that stores state and functions for interacting with
* MCP3008 Chip
*/
class Adafruit_MCP3008 {
public:
~Adafruit_MCP3008();
bool begin(uint8_t cs = SS, SPIClass *theSPI = &SPI);
bool begin(uint8_t sck, uint8_t mosi, uint8_t miso, uint8_t cs);
int readADC(uint8_t channel);
int readADCDifference(uint8_t differential);
private:
Adafruit_SPIDevice *spi_dev = NULL; ///< Pointer to SPI bus interface
uint8_t _cs;
uint8_t buffer[3];
int SPIxADC(uint8_t channel, bool differential);
};
#endif