/
GroveColorSensor.h
67 lines (56 loc) · 1.6 KB
/
GroveColorSensor.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
/****************************************************************************/
// Hardware: Grove - I2C Color Sensor
// Arduino IDE: Arduino-1.6
//
// Refactored version of the library by FrankieChu - www.seeedstudio.com
//
/******************************************************************************/
#ifndef GROVECOLORSENSOR
#define GROVECOLORSENSOR
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Registers.h>
class GroveColorSensor {
public:
// Color Sensor LED Status
int ledStatus;
// Default constructor
GroveColorSensor();
// Constructor with parameters
GroveColorSensor(
const int& triggerMode
, const int& interruptSource
, const int& interruptMode
, const int& gainAndPrescaler
, const int& sensorAddress);
void readRGB();
void readRGB(int* red, int* green, int* blue);
void calculateCoordinate();
void clearInterrupt();
private:
// Set trigger mode. Including free mode, manually mode, single synchronization mode or so.
void setTimingReg();
// Set interrupt source
void setInterruptSourceReg();
// Set interrupt mode
void setInterruptControlReg();
// Set gain value and pre-scaler value
void setGain();
// Start ADC of the colour sensor
void setEnableADC();
// Used for storing the colour data
int readingdata_[8];
int green_;
int red_;
int blue_;
int clear_;
int triggerMode_;
int interruptSource_;
int interruptMode_;
int gainAndPrescaler_;
int sensorAddress_;
};
#endif