micro-ELC
LoadAdjustRelayParallelBinary.h
Go to the documentation of this file.
1#ifndef LOAD_ADJUST_RELAY_PARALLEL_BINARY_H
2#define LOAD_ADJUST_RELAY_PARALLEL_BINARY_H
3#include "../LoadAdjust.h"
4#include "RelaysDriver.h"
5#include <Arduino.h>
10template <byte N>
12public:
20 LoadAdjustRelayParallelBinary(RelaysDriver& _relaysDriver, bool _activeRelaysIncreaseLoad = false)
21 : driver(_relaysDriver)
22 {
23 activeRelaysIncreaseLoad = _activeRelaysIncreaseLoad;
24 }
25 void setLoad(float load)
26 {
27 uint16_t setting = constrain(load, 0.0, 1.0) * ((1 << N) - 1); // convert [0.0, 1.0] to [0, 2^n-1]
28 if (!activeRelaysIncreaseLoad) { // if active relays decrease the load (open the circuit to a resistor) (activeRelaysIncreaseLoad==false)
29 setting = ~setting; // then a load of 1 should turn off all relays, and a load of 0 should activate all the relays
30 }
31 driver.set(setting);
32 }
33 void begin()
34 {
35 driver.begin();
36 }
37};
38#endif
This class defines an interface for any type of adjustable electrical load.
Definition: LoadAdjust.h:7
load adjustor that switches relays or other switches on and off in a binary pattern
Definition: LoadAdjustRelayParallelBinary.h:11
void setLoad(float load)
set a new value for the adjustable load
Definition: LoadAdjustRelayParallelBinary.h:25
void begin()
set up pin states
Definition: LoadAdjustRelayParallelBinary.h:33
RelaysDriver & driver
Definition: LoadAdjustRelayParallelBinary.h:13
LoadAdjustRelayParallelBinary(RelaysDriver &_relaysDriver, bool _activeRelaysIncreaseLoad=false)
load adjustor that switches relays or other switches on and off in a binary pattern
Definition: LoadAdjustRelayParallelBinary.h:20
bool activeRelaysIncreaseLoad
Definition: LoadAdjustRelayParallelBinary.h:14
This class defines an interface for any class that can control an array of relays.
Definition: RelaysDriver.h:8
virtual void begin()=0
this function should be called on startup. It sets up pinmodes.
virtual void set(uint16_t bits)=0
activate relays corresponding to a bit that's 1.