class LedInterface {
public:
virtual void begin() = 0;
virtual void toggle() = 0;
virtual void on() = 0;
virtual void off() = 0;
};
template <uint8_t Pin> class Led : public LedInterface {
public:
virtual void begin() { pinMode(Pin, OUTPUT); }
virtual void toggle() { digitalWrite(Pin, !digitalRead(Pin)); }
virtual void on() { digitalWrite(Pin, HIGH); }
virtual void off() { digitalWrite(Pin, LOW); }
};
struct Thresholds {
int8_t Min;
int8_t Max;
LedInterface* Device;
};
Led<4> LedRC; // Red Cold
Led<5> LedYC; // Yellow Cold
Led<6> LedOk; // All Ok
Led<7> LedYW; // Yellow Warm
Led<8> LedRW; // Red Warm
Thresholds TempThres[] {
{-127, 10, &LedRC},
{11, 15, &LedYC},
{16, 22, &LedOk},
{23, 28, &LedYW},
{28, 127, &LedRW},
};
void setup() {
Serial.begin(115200);
for (auto& L : TempThres) {
L.Device->begin();
L.Device->on();
}
randomSeed(A0);
}
void loop() {
int Temperature = random(-10, 55);
Serial.println(Temperature);
for (auto& T : TempThres) {
if (Temperature >= T.Min && Temperature <= T.Max) {
T.Device->on();
} else {
T.Device->off();
}
}
delay(5000);
}