-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelays.cpp
47 lines (38 loc) · 821 Bytes
/
relays.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
45
46
47
#include "relays.h"
#include <Arduino.h>
#define SYSTEM_MA 40
#define TOTAL_MA_MAX 4000
namespace Relays {
uint16_t total_ma = SYSTEM_MA;
Relay::Relay(uint8_t a, uint16_t b):
pin(a), ma_rating(b) {
pinMode(pin, OUTPUT);
}
bool Relay::set(bool state) {
bool return_value = false;
switch (state) {
case HIGH:
if (total_ma + ma_rating <= TOTAL_MA_MAX) {
total_ma += ma_rating;
digitalWrite(pin, HIGH);
return_value = true;
}
break;
case LOW:
total_ma -= ma_rating;
digitalWrite(pin, LOW);
break;
}
return return_value;
}
Relay relays[RELAY_COUNT] = {
{0, 470},
{1, 470},
{2, 470},
{3, 470},
{4, 470},
{5, 470},
{6, 470},
{7, 470}
};
}