-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinealSensor.h
More file actions
71 lines (58 loc) · 2.11 KB
/
LinealSensor.h
File metadata and controls
71 lines (58 loc) · 2.11 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
60
61
62
63
64
65
66
67
68
69
70
71
/**********************************************************************
* LinealSensor library
* Arduino library to control a lineal sensor using an analog adapter
* the adapter signal must be conected to one of the analog pins
* lineal sensor are pH probes, ORP probes.
* Including two point calibration procedure.
*
*
*
*
* version 0.1 ALPHA 22/09/2015
* Author: Jaime García @peninquen
* License: Apache License Version 2.0.
*
/**********************************************************************/
#ifndef LinealSensor_h
#define LinealSensor_h
#include "Arduino.h"
#include <EEPROM.h>
#define BUFFERSIZE 10
#define MAGIC_NUMBER 1234 // byte number to check valid values in EEPROM
struct calibration {
short magicNumber;
short reference; // pH reference value x100
short rawData; // ADC value
calibration(short mN = 0, short ref = 0, short rData = 0 ) {
magicNumber = mN;
reference = ref;
rawData = rData;
}
};
class LinealSensor {
public:
//constructor
LinealSensor();
// Setup instance variables
void begin(int sensorPin, unsigned short interval, calibration *cal, byte calAddress, unsigned short calNum);
// calibrate and write data on EEPROM
calibration &calibrate(byte calAddress, calibration &cal);
// check interval and update data, interval must be greater than loop cycle
boolean refreshData();
// read _counter value in defined units
short read();
// is a new data available?
boolean available();
private:
int _sensorPin; // Analog pin conected to pH sensor adapter
boolean _flag; // true when data is available, false when data is readed
unsigned long _processTime; // last time process
unsigned short _interval; // time [miliseconds] between adquisition data
unsigned short _rawData[BUFFERSIZE]; // raw data from ADC
unsigned short _index;
unsigned short _calNum; // number of calibration references
calibration *_cal; // Calibration reference
float _offset;
float _slope;
};
#endif