const int pinR = 8,
pinG = 7,
pinB = 6;
class Blinker
{
private:
int pin_ = LED_BUILTIN;
bool on_ = false;
bool working = false;
uint32_t last_time_ = 0;
uint32_t delay_ = 1000;
public:
Blinker(){};
Blinker(int p)
{
pin_ = p;
};
Blinker(int p, uint32_t d)
{
pin_ = p;
delay_ = d;
};
~Blinker()
{
};
void init()
{
pinMode(pin_, OUTPUT);
working = false;
}
void init(int p)
{
pin_ = p;
init();
}
void init(int p, uint32_t d)
{
pin_ = p;
delay_ = d;
init();
}
void tick()
{
if (working)
if ( millis() - last_time_ > delay_)
{
last_time_ = millis();
on_ = !on_;
digitalWrite(pin_, on_);
}
};
void setDelay(uint32_t d)
{
delay_ = d;
};
void write()
{
digitalWrite(pin_, on_);
}
void switchOn()
{
on_ = true;
write();
}
void swithchOff()
{
on_ = false;
write();
}
void start()
{
working = true;
};
void stop()
{
working = false;
};
};
Blinker r;
Blinker g;
void setup()
{
r.init(pinR, 1000);
g.init(pinG, 500);
r.start();
}
void loop()
{
r.tick();
g.tick();
}