-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAirPump.cpp
45 lines (33 loc) · 841 Bytes
/
AirPump.cpp
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
/*
* (C) 2016 Onwrikbaar <[email protected]>
*/
#include <math.h>
#include "AirPump.h"
#define PUMP_SPEED_MIN 120
#define PUMP_SPEED_MAX 240
// Constructor.
AirPump::AirPump(uint8_t pn) : OutputPin(pn)
{
// Nothing more to do.
}
void AirPump::setSpeed(uint8_t speed)
{
// Note: For a 3V pump the on-time must be scaled down proportionally if the supply voltage exceeds 3V.
if (speed != previousSpeed) { // Only call the library if the value has changed.
pwmWrite(previousSpeed = speed);
}
}
void AirPump::start()
{
setSpeed(PUMP_SPEED_MIN);
}
void AirPump::stop()
{
setSpeed(0);
}
void AirPump::setFlowRate(float rate)
{
if (rate >= 0.0 && rate <= 1.0) {
setSpeed(PUMP_SPEED_MIN + round(rate * (float)(PUMP_SPEED_MAX - PUMP_SPEED_MIN)));
}
}