-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalibrator.cpp
More file actions
48 lines (40 loc) · 851 Bytes
/
Calibrator.cpp
File metadata and controls
48 lines (40 loc) · 851 Bytes
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
/*
Calibrator.cpp - Library for calibrating sensors hooked to analog inputs.
Calibrator is released under the Apache 2.0 license. See the included LICENSE file.
Copyright 2013 Julian Vidal
https://github.com/poisa/Calibrator
*/
#include "Arduino.h"
#include "Calibrator.h"
Calibrator::Calibrator()
{
reset();
}
void Calibrator::setValue(int currentValue)
{
if (currentValue > _maxValue) {
_maxValue = currentValue;
}
if (currentValue < _minValue) {
_minValue = currentValue;
}
};
int Calibrator::getValue(int currentValue)
{
currentValue = map(currentValue, _minValue, _maxValue, 0, 1023);
currentValue = constrain(currentValue, 0, 1023);
return currentValue;
}
int Calibrator::getMin()
{
return _minValue;
}
int Calibrator::getMax()
{
return _maxValue;
}
void Calibrator::reset()
{
_minValue = 1023;
_maxValue = 0;
}