/*
* animation lumineuse de la gare de La Roche
* basée sur un ATtiny85
* 5 pins utilisées : 0 à 4
* pin 0 = entrée clients, toujours allumée
* pin 1 = bureau de vente, avec employé
* pin 2 = salle d'attente, parfois éteinte
* pin 3 = bureau, parfois allumé
* pin 4 = etage, parfois allumé
* pin 5 = entrée analogique pour faire de l'aléatoire
* une temporisation de 10 secondes change l'état des leds
*
* Version 1.01 du 15 juin 2017 Dominique (Locoduino)
*lien: https://www.locoduino.org/spip.php?article285
*/
// constantes
const int tempo1 = 5000;
const int tempo2 = 10000;
// variables
byte leds = 0B00011111; // état des leds - - - 4 3 2 1 0
unsigned long temps;
byte randBit, randByte;
int tempo;
void setup() {
pinMode(0,OUTPUT); // entrée clients
pinMode(1,OUTPUT); // bureau de vente
pinMode(2,OUTPUT); // salle d'attente
pinMode(3,OUTPUT); // bureau
pinMode(4,OUTPUT); // etage
temps = millis();
tempo = tempo1;
randomSeed(analogRead(5));
}
void loop() {
for (int i=0; i<5; i++) {
digitalWrite(i, bitRead(leds, i));
}
if (millis() > temps+tempo) {
temps = millis();
if (tempo == tempo1) {
tempo = tempo2;
} else {
tempo = tempo1;
}
randBit = random(2,5); // donc 2 ou 3 ou 4
randByte = 0;
randByte = bitSet(randByte,randBit);
leds = leds ^ randByte;
}
}