Noiasca Tool Kit
Several helper functions and classes to make life with Arduino easier
Public Member Functions | List of all members
Trafficlight< T > Class Template Reference

traffic light More...

#include <Noiasca_led.h>

Public Member Functions

 Trafficlight (T &obj)
 constructor for a traffic light More...
 
void begin ()
 start hardware More...
 
void setInterval (uint16_t _on)
 set on times More...
 
int setSequenceIndex (uint8_t index, uint8_t newState, uint16_t newInterval)
 set the sequence parameters More...
 
int setSequenceMax (uint8_t newMax)
 set the number of sequences More...
 
void setMode (Mode newMode)
 set the current Mode of the traffic light More...
 
void setOnStateChange (Callback funcPtr)
 set the callback function onStateChange More...
 
void setOnSequenceChange (Callback funcPtr)
 set the callback function onSequnceChange More...
 
void setOnColor (uint16_t actual, uint32_t _on)
 set the color for a traffic light More...
 
void setOffColor (uint32_t _off)
 set the color for a traffic light More...
 
void setState (uint8_t newState)
 set the state of the traffic light More...
 
void update (uint32_t currentMillis=millis())
 check if update is necessary More...
 

Detailed Description

template<class T>
class Trafficlight< T >

traffic light

state // 0 OFF, 1 RED, 2 REDYELLOW, 3 GREEN, 4 YELLOW, 5 YELLOWBLINK, 6 GREENBLINK

mode // 0 manual // 1 automatic // 2 redgreenonly / 3 automaticAT

interval as array sequence (order, interval)
doesn't inherit from LedBase

Constructor & Destructor Documentation

◆ Trafficlight()

template<class T >
Trafficlight< T >::Trafficlight ( T &  obj)
inline

constructor for a traffic light

Parameters
obja object with 3 lamps

Member Function Documentation

◆ begin()

template<class T >
void Trafficlight< T >::begin ( )
inline

start hardware

Will do the necessary steps to initialize the hardware pins. Call this function in your setup().

◆ setInterval()

template<class T >
void Trafficlight< T >::setInterval ( uint16_t  _on)
inline

set on times

Set the on interval.

Parameters
_onthe on interval

◆ setSequenceIndex()

template<class T >
int Trafficlight< T >::setSequenceIndex ( uint8_t  index,
uint8_t  newState,
uint16_t  newInterval 
)
inline

set the sequence parameters

By default there are 4 predefined sequences - you can define up to 8. You can modify each entry including the durance of each interval (in ms). For example: in Austria or Ukraine you can add (insert) a green blinking light sequnce

Parameters
indexthe number of the sequnce.
newStatethe state (the face) of the sequence.
newIntervalthe interval (durance) of the sequence in ms.

◆ setSequenceMax()

template<class T >
int Trafficlight< T >::setSequenceMax ( uint8_t  newMax)
inline

set the number of sequences

By default there are 4 predefined sequences - you can define up to 8.

Parameters
newMaxthe maximum number of sequences

◆ setMode()

template<class T >
void Trafficlight< T >::setMode ( Mode  newMode)
inline

set the current Mode of the traffic light

default state is Trafficlight::Mode::AUTOMATIC, but you can change it to Trafficlight::Mode::AUTOMATIC

Parameters
newModeset to Trafficlight::Mode::AUTOMATIC or Trafficlight::Mode::Manual

◆ setOnStateChange()

template<class T >
void Trafficlight< T >::setOnStateChange ( Callback  funcPtr)
inline

set the callback function onStateChange

a callback function receives state changes from the car traffic light

Parameters
funcPtrthe callback function
Todo:
clearify usage of this vs onSequnceChange

◆ setOnSequenceChange()

template<class T >
void Trafficlight< T >::setOnSequenceChange ( Callback  funcPtr)
inline

set the callback function onSequnceChange

a callback function receives changes of the sequence (faces). For example to keep another traffic light in sync, like a pedestrain trafficlight or the crossing line.

Parameters
funcPtrthe callback function

◆ setOnColor()

template<class T >
void Trafficlight< T >::setOnColor ( uint16_t  actual,
uint32_t  _on 
)
inline

set the color for a traffic light

Parameters
actual0 for red, 1 for yellow, 2 for green
_onthe color code in HEX

◆ setOffColor()

template<class T >
void Trafficlight< T >::setOffColor ( uint32_t  _off)
inline

set the color for a traffic light

Parameters
_offthe color code in HEX

◆ setState()

template<class T >
void Trafficlight< T >::setState ( uint8_t  newState)
inline

set the state of the traffic light

Parameters
newStatethe new state

◆ update()

template<class T >
void Trafficlight< T >::update ( uint32_t  currentMillis = millis())
inline

check if update is necessary

This is the "run" function. Call this function in loop() to make the effect visible.

Parameters
currentMillisyou can handover a millis timestamp