class Renault {
private:
byte _pin1;
byte _pin2;
unsigned long _tiempo;
bool prendido = false;
public:
int Renault::contador = 0; // contador para la primera vez.
void iniciar(byte a, byte b)
{
_pin1 = a;
_pin2 = b;
pinMode(_pin1,OUTPUT);
pinMode(_pin2,OUTPUT);
_tiempo = millis();
}
void encender(byte _pin1,byte _pin2)
{
digitalWrite(_pin1, HIGH);
digitalWrite(_pin2, HIGH);
}
void apagar(byte _pin1, byte _pin2)
{
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
}
void encenderchulos(byte _pin1,byte _pin2, long tiempo)
{
tiempo = tiempo * 1000 ;
if (contador == 0)
{
void(iniciar(_pin1,_pin2));
encender (_pin1, _pin2) ;
contador = 1;
}
if(millis() -_tiempo >= tiempo) {
if(prendido == false) {
encender (_pin1, _pin2) ;
} else {
apagar( _pin1, _pin2) ;
}
_tiempo = millis();
prendido = !prendido;
}
}
};
Renault Motor1;
Renault Motor2;
Renault R9;
Renault MEGANE;
// podemos omitir esto **(1)
const byte Pinled_L2 = 2;
const byte Pinled_L3 = 3;
const byte Pinled_L4 = 4;
const byte Pinled_L5 = 5;
const byte Pinled_L6 = 6;
const byte Pinled_L7 = 7;
const byte Pinled_L8 = 8;
const byte Pinled_L9 = 9;
const byte Pinled_L10 = 10;
const byte Pinled_L11 = 11;
const byte Pinled_L12 = 12;
const byte Pinled_L13 = 13;
const byte Pinled_L14 = 14;
const byte Pinled_L15 = 15;
const byte Pinled_L16 = 16;
const byte Pinled_L17 = 17;
const byte Pinled_L18 = 18;
const byte Pinled_L19 = 19;
const byte Pinled_L20 = 20;
void setup()
{
Serial.begin(9600);
Motor2.iniciar(Pinled_L16 ,Pinled_L17);
}
void loop()
{
Motor1.encenderchulos(Pinled_L2,Pinled_L3,2);
MEGANE.encenderchulos(Pinled_L4,Pinled_L5,1);
R9.encenderchulos(Pinled_L8,Pinled_L9,7);
Motor2.encender(Pinled_L16,Pinled_L17);
}