Hallo Zusammen,
ich habe aktuell ein kleines Problem mit dem Programm, sowohl bei der Verwendung der Bibliothek von @noiasca wie auch mit dem ursprünglichen Code... 
Und zwar habe ich folgende "Blink-Sequenz" erstellt:
750 ms LED 1 und 2 ON
1500 ms LED 1 OFF 750ms LED 2 OFF
750 ms LED 2 ON
Es sollte also einmal beide LEDs aufleuchten, dann nur eine, dann wieder beide - dann nur eine.... immer im gleichen Rythmus.
Das Problem - nach einiger Zeit fangen die beiden LEDs an, außeinander zu laufen... ich vermute mal, das könnte das Problem sein, welches @my_xy_projekt in Reply #4 erwähnt hat?
Liegt es daran, dass millis() für beide LEDs nacheinander aufgerufen wird - und dadurch mit der Zeit einfach kleinere Differenzen aufaddiert werden?
Wie könnte ich dieses Problem angehen?
hier der aktuell verwendete Code dafür:
// PWM functionallity not required
const byte NavigationLightsPin = 7;
const long NavigationLightsOnTime = 750;
const long NavigationLightsOffTime = 1500;
const byte PositionLightsPin = 2;
const byte PositionLightsOnTime = 750;
const byte PositionLightsOffTime = 750;
class Flasher {
protected:
const byte ledPin;
const uint32_t onPhase;
const uint32_t offPhase;
uint32_t timeMarker = 0;
enum _step : byte {Start, OnPhase, OffPhase};
Flasher::_step step = _step::Start;
public:
Flasher(const byte ledPin, const unsigned long onPhase, const unsigned long offPhase): ledPin(ledPin), onPhase(onPhase), offPhase(offPhase) {}
void run(byte & blinkAmount) {
uint32_t now = millis();
switch (step) {
case _step::Start:
if (blinkAmount) {
digitalWrite(ledPin, HIGH);
step = _step::OnPhase;
timeMarker = now;
}
break;
case _step::OnPhase:
if (now - timeMarker >= onPhase) {
digitalWrite(ledPin, LOW);
step = _step::OffPhase;
timeMarker = now;
}
break;
case _step::OffPhase:
if (now - timeMarker >= offPhase) {
if (blinkAmount > 0) blinkAmount--;
step = _step::Start;
}
}
}
void init() {
pinMode(ledPin, OUTPUT);
}
};
enum FlashingGroup : byte {NAVI, TORPEDO, BEACON, POSITION};
Flasher flashingGroup[] =
{
{NavigationLightsPin, NavigationLightsOnTime, NavigationLightsOffTime},
{TorpedoLaunchLightPin, TorpedoLaunchOnTime, TorpedoLaunchOffTime},
{BeaconLightPin, BeaconLightOnTime, BeaconLightOffTime},
{PositionLightsPin, PositionLightsOnTime, PositionLightsOffTime},
};
void setup()
{
for (Flasher &flash : flashingGroup) flash.init();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
byte tmp = 1;
flashingGroup[BEACON].run(tmp);
flashingGroup[NAVI].run(tmp);
flashingGroup[POSITION].run(tmp);
}