This repository has been archived on 2024-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
zamek-hswro/DualColorLed.cpp

38 lines
801 B
C++
Raw Permalink Normal View History

2017-12-17 11:31:13 +00:00
#include "DualColorLed.h"
#include <Arduino.h>
DualColorLed::DualColorLed(IGpio& redGpio, IGpio& greenGpio):
redGpio(redGpio),
greenGpio(greenGpio),
currentState(State::Off)
{
redGpio.write(false);
greenGpio.write(false);
redGpio.setMode(IGpio::Mode::Output);
greenGpio.setMode(IGpio::Mode::Output);
}
void DualColorLed::setState(DualColorLed::State newState)
{
if(currentState == newState)
return;
currentState = newState;
switch(newState) {
case State::Off:
redGpio.write(false);
greenGpio.write(false);
return;
case State::Red:
redGpio.write(true);
greenGpio.write(false);
return;
case State::Green:
redGpio.write(false);
greenGpio.write(true);
return;
}
}