micro-ELC
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RelaysDriverBasic< N > Class Template Reference

This class controls an array of relays in a simple way. More...

#include <RelaysDriverBasic.h>

Inheritance diagram for RelaysDriverBasic< N >:
Inheritance graph
[legend]
Collaboration diagram for RelaysDriverBasic< N >:
Collaboration graph
[legend]

Public Member Functions

template<typename T , size_t n>
 RelaysDriverBasic (bool _active, const T(&pins)[n])
 constructor. More...
 
void begin ()
 this function should be called on startup. It sets up pinmodes. More...
 
void set (uint16_t bits)
 activate relays corresponding to a bit that's 1. More...
 
virtual void set (uint16_t bits)=0
 activate relays corresponding to a bit that's 1. More...
 
virtual void begin ()=0
 this function should be called on startup. It sets up pinmodes. More...
 

Protected Member Functions

void write (byte relay, bool setState)
 set a specific relay to a state, just to keep the code that actually drives a relay separate More...
 

Protected Attributes

uint8_t pin [N]
 
bool active
 

Detailed Description

template<uint8_t N>
class RelaysDriverBasic< N >

This class controls an array of relays in a simple way.

Note
This class could also work with transistors or MOSFETs, which are better than mechanical relays in terms of switching time and lifetime. It uses GPIO pins, and has no compensation for switching time.
Parameters
Nhow many relays need to be controlled. N must be <=16 (because set() uses a 16 bit variable).

Constructor & Destructor Documentation

◆ RelaysDriverBasic()

template<uint8_t N>
template<typename T , size_t n>
RelaysDriverBasic< N >::RelaysDriverBasic ( bool  _active,
const T(&)  pins[n] 
)
inline

constructor.

Parameters
_activedo the switches activate on a HIGH or LOW output?
pins{list, of, pins}

Member Function Documentation

◆ begin()

template<uint8_t N>
void RelaysDriverBasic< N >::begin ( )
inlinevirtual

this function should be called on startup. It sets up pinmodes.

Implements RelaysDriver.

◆ set()

template<uint8_t N>
void RelaysDriverBasic< N >::set ( uint16_t  bits)
inlinevirtual

activate relays corresponding to a bit that's 1.

Note
1 is the LSB, e.g. 001 turns on the first relay.
Parameters
bitsThink of this number as an array of bits. Bits that there is no relay for are ignored.

Implements RelaysDriver.

◆ write()

template<uint8_t N>
void RelaysDriverBasic< N >::write ( byte  relay,
bool  setState 
)
inlineprotected

set a specific relay to a state, just to keep the code that actually drives a relay separate

Parameters
relay[0,N) the relay to write to
setStatetrue=active false=inactive

Member Data Documentation

◆ active

template<uint8_t N>
bool RelaysDriverBasic< N >::active
protected

◆ pin

template<uint8_t N>
uint8_t RelaysDriverBasic< N >::pin[N]
protected

The documentation for this class was generated from the following file: