/* attiny85 4 led aleatoire millis

   allumage et extinction aleatoires de 4 LED
   simulation: https://wokwi.com/projects/380390648027228161

               Brochage ATtiny85

               =|1  U  8|= VCC
     Led3 <--3 =|2     7|= 2--> Led2
  random -->A2 =|3     6|= 1--> Led1
           GND =|4     5|= 0--> Led0
*/

const byte Led1 = 0;
const byte Led2 = 1;
const byte Led3 = 2;
const byte Led4 = 3;
bool led1State;
bool led2State;
bool led3State;
bool led4State;
unsigned long led1PreviousMillis = 0;
unsigned long led2PreviousMillis = 0;
unsigned long led3PreviousMillis = 0;
unsigned long led4PreviousMillis = 0;
unsigned int led1Interval = 0;
unsigned int led2Interval = 0;
unsigned int led3Interval = 0;
unsigned int led4Interval = 0;

void setup() {
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  pinMode(Led4, OUTPUT);
  randomSeed(analogRead(A2));
} // fin setup

void loop() {
  unsigned long currentMillis = millis();
  byte t1Led1 = random(3, 10);
  byte t2Led1 = random(5, 10);
  byte t1Led2 = random(3, 10);
  byte t2Led2 = random(5, 10);
  byte t1Led3 = random(3, 10);
  byte t2Led3 = random(5, 10);
  byte t1Led4 = random(3, 10);
  byte t2Led4 = random(5, 10);
  // définition des durees en sec: allumage (indice 1) et extinction (indice 2)
  unsigned int led1Interval1 = 1000 * t1Led1;
  unsigned int led1Interval2 = 1000 * t2Led1;
  unsigned int led2Interval1 = 1000 * t1Led2;
  unsigned int led2Interval2 = 1000 * t2Led2;
  unsigned int led3Interval1 = 1000 * t1Led3;
  unsigned int led3Interval2 = 1000 * t2Led3;
  unsigned int led4Interval1 = 1000 * t1Led4;
  unsigned int led4Interval2 = 1000 * t2Led4;

  if (currentMillis - led1PreviousMillis >= led1Interval) {
    led1PreviousMillis = currentMillis;
    if (led1State == LOW) {
      led1State = HIGH;
      led1Interval = led1Interval2;
    }
    else {
      led1State = LOW;
      led1Interval = led1Interval1;
    }
    digitalWrite(Led1, led1State);
  }

  if (currentMillis - led2PreviousMillis >= led2Interval) {
    led2PreviousMillis = currentMillis;
    if (led2State == LOW) {
      led2State = HIGH;
      led2Interval = led2Interval1;
    }
    else {
      led2State = LOW;
      led2Interval = led2Interval2;
    }
    digitalWrite(Led2, led2State);
  }

  if (currentMillis - led3PreviousMillis >= led3Interval) {
    led3PreviousMillis = currentMillis;
    if (led3State == LOW) {
      led3State = HIGH;
      led3Interval = led3Interval2;
    }
    else {
      led3State = LOW;
      led3Interval = led3Interval1;
    }
    digitalWrite(Led3, led3State);
  }
  if (currentMillis - led4PreviousMillis >= led4Interval) {
    led4PreviousMillis = currentMillis;
    if (led4State == LOW) {
      led4State = HIGH;
      led4Interval = led4Interval2;
    }
    else {
      led4State = LOW;
      led4Interval = led4Interval1;
    }
    digitalWrite(Led4, led4State);
  }
} // fin loop
ATTINY8520PU