Skip to content

Commit 1b12007

Browse files
committed
Fixed voltage algorithm. (#182)
1 parent c2d573d commit 1b12007

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/VoltageSensor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "VoltageSensor.h"
22

3-
VoltageSensor::VoltageSensor(int *const pins) : Device<float>(pins) {}
3+
VoltageSensor::VoltageSensor(int r1, int r2, int *const pins) : _factor((float) (r1 + r2) / r2), Device<float>(pins) {}
44

55
void VoltageSensor::initialize() { pinMode(_pins[0], INPUT); }
66

7-
float VoltageSensor::read() { return (float) analogRead(_pins[0]) * 5 / 1023; }
7+
float VoltageSensor::read() { return (float) analogRead(_pins[0]) * _factor * 5 / 1023; }

src/VoltageSensor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#include "Device.h"
66

77
class VoltageSensor : public Device<float> {
8+
protected:
9+
float _factor;
810
public:
9-
VoltageSensor(int *const pins);
11+
VoltageSensor(int r1, int r2, int *const pins);
1012
void initialize();
1113
float read();
1214
};

0 commit comments

Comments
 (0)