Arduino 6, AŽD přejezdové zařízení se závorami (LED + zvuk + serva)

Použité komponenty:
1 x Arduino Pro Mini (Nano) - Aliexpress (cca 35 CZK klon)
1 x DFPlayer MP3 (Mp3-TF-16P) - AliExpress (cca 30 CZK verze mp3-tf-16p) + doporučujeme zesilovač zvuku
4 x led červená
2 x led bílá
1 x vypínač dle volby, možné i magnetické spínače a systém relé (to je na každém, jak potřebuje)
1 x odpor 10 k pro spínač
6 x odpor 330 ohmů pro led
1 x odpor 1 k pro pin TX propojení modulů (ochrana)
1 x microSD paměťová karta - formát FAT32
1 x repro 3 W 4 ohmy
2 x modelářské servo


Program:
Program verze 2.5 - celý komplet plní všechny cykly jako na pravé železnici. 
Stav klidu - blikají bílá světla - střídání mezi výstražníky.
Stav výstrahy - sepnutím vypínače, relé, či jak si to uděláte se přepne do stavu výstrahy:
1) sepnou červená světla se zvukovým znamením
2) po určitém čase se otočí serva pro zavření závor a v koncové poloze závory se vypne zvuková výstraha
3) blikají jen červené
4) rozepnutí vypínače - červené blikají a serva se otočí, závory jdou nahoru
5) závory v koncové poloze vypnou červená světla
6) doba klidu bez světel - 30 km/hod rychlost přes přejezd
7) rozblikají se bílé

microSD karta - do kořenového adresáře nahrajte zvuk s názvem 0001.mp3
Zvuk AŽD 71 můžete stáhnout zde.

Zvuky lze použít i AŽD97 a typ SSSR /houkačka/.

Program:

// Program AZD prejezd LED červená + bílá + servo
#include <SoftwareSerial.h>
#include <Servo.h>  
Servo servo1;                                                                 // společný pin pro serva 12
SoftwareSerial mySerial(2, 3); // RX, TX                                      // piny pro zvukový modul
uint8_t play1[10] = { 0X7E, 0xFF, 0x06, 0X03, 00, 00, 0x01, 0xFE, 0xF7, 0XEF}; // protokol MP3 komunikace
int red1 = 4;                                                                 // pravá červená led
int red2 = 5;                                                                 // levá červená led
int white1 = 6;                                                              // bílá led na jednom výstražníku
int white2 = 7;                                                              // bílá led na druhém výstražníku
int ledDelay = 500;                                                           // zpoždění mezi blikáním /neměnit/ 
bool wait = true;                                                             // podmínky cyklů
bool wait2 = true;
const int  buttonPin = 13;                                                    // pin vypínače
int buttonPushCounter = 0;   // počítadlo stlačení tlačítka  (příprava na spínač)
int buttonState = 0;         // současný stav tlačítka
int lastButtonState = 0;     
int pos = 0;                  // servo
int value = 0;                // servo
//vejrov.cz

void setup()  
{
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(white1, OUTPUT);
pinMode(white2, OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}

void loop()
{
buttonState = digitalRead(buttonPin);  

         if (buttonState == HIGH) {
 wait = true;
 if (wait2 == true){
  for (int i=0; i<10; i++) {mySerial.write( play1[i]);}                 // první cyklus červené + zvuk = přednávěst
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } //vejrov.cz
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); //vejrov.cz
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); //vejrov.cz
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  
  for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
   servo1.attach(12);                                                      // druhý cyklus červené + zvuk + servo = návěst
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  }
  for (pos = 90; pos >= 89; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 89; pos >= 88; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 88; pos >= 87; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 87; pos >= 86; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 86; pos >= 85; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 85; pos >= 84; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 84; pos >= 83; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 83; pos >= 82; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 82; pos >= 81; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 81; pos >= 80; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}//vejrov.cz
delay(40); 
  for (pos = 80; pos >= 79; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 79; pos >= 78; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 78; pos >= 77; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 77; pos >= 76; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  }
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  }//vejrov.cz
  for (pos = 76; pos >= 75; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 75; pos >= 74; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 74; pos >= 73; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 73; pos >= 72; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 72; pos >= 71; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 71; pos >= 70; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 70; pos >= 69; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 69; pos >= 68; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 68; pos >= 67; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 67; pos >= 66; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40);
  for (pos = 66; pos >= 65; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 65; pos >= 64; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 64; pos >= 63; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}//vejrov.cz
delay(40); 
  for (pos = 63; pos >= 62; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
    for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  }
  for (pos = 52; pos >= 61; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 61; pos >= 60; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 60; pos >= 59; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 59; pos >= 58; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 58; pos >= 57; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 57; pos >= 56; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 56; pos >= 55; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); //vejrov.cz
  for (pos = 55; pos >= 54; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40);
  for (pos = 54; pos >= 53; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 53; pos >= 52; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 52; pos >= 51; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 51; pos >= 50; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 50; pos >= 49; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 49; pos >= 48; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
   for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  for (pos = 48; pos >= 47; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 47; pos >= 46; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); //vejrov.cz
  for (pos = 46; pos >= 45; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 45; pos >= 44; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 44; pos >= 43; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 43; pos >= 42; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40);
  for (pos = 42; pos >= 41; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 41; pos >= 40; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 40; pos >= 39; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 39; pos >= 38; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 38; pos >= 37; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 37; pos >= 36; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 36; pos >= 35; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); //vejrov.cz
  for (pos = 35; pos >= 34; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
   for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
    for (int i=0; i<10; i++) {mySerial.write( play1[i]);}
 delay(10); 
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
  for (pos = 34; pos >= 33; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 33; pos >= 32; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 32; pos >= 31; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 31; pos >= 30; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40);
  for (pos = 30; pos >= 29; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 29; pos >= 28; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 28; pos >= 27; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 27; pos >= 26; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 26; pos >= 25; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 25; pos >= 24; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 24; pos >= 23; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); //vejrov.cz
  for (pos = 23; pos >= 22; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  for (pos = 22; pos >= 21; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 21; pos >= 20; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 20; pos >= 19; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 19; pos >= 18; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40);
  for (pos = 18; pos >= 17; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 17; pos >= 16; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 16; pos >= 15; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 15; pos >= 14; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 14; pos >= 13; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 13; pos >= 12; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 12; pos >= 11; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
  for (pos = 11; pos >= 10; pos -=2){
  servo1.write(pos);  
  value = servo1.read();
  Serial.println(value);}
delay(40); 
   for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
servo1.detach();
}

 wait2 = false;                                                       // cyklus červené bez zvuku - závory dole
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 delay(100);//vejrov.cz
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
delay(ledDelay); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
        }
        else {
 wait2 = true;
    if (wait == true){
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {                        // zvedání závor s červeným světlem
    analogWrite(red1, fadeValue);
    delay(10);
  } 
  servo1.attach(12);
  for (pos = 10; pos <= 11; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 11; pos <= 12; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 12; pos <= 13; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 13; pos <= 14; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 14; pos <= 15; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 15; pos <= 16; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 16; pos <= 17; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 17; pos <= 18; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 18; pos <= 19; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 19; pos <= 20; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 20; pos <= 21; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 21; pos <= 22; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 22; pos <= 23; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  for (pos = 23; pos <= 24; pos +=2){
  servo1.write(pos);   
  value = servo1.read();//vejrov.cz
  Serial.println(value); }
delay(40); 
  for (pos = 24; pos <= 25; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 25; pos <= 26; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 26; pos <= 27; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 27; pos <= 28; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 28; pos <= 29; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 29; pos <= 30; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 30; pos <= 31; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 31; pos <= 32; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 32; pos <= 33; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 33; pos <= 34; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 34; pos <= 35; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 35; pos <= 36; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
  for (pos = 36; pos <= 37; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 37; pos <= 38; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 38; pos <= 39; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); //vejrov.cz
  for (pos = 39; pos <= 40; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 40; pos <= 41; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 41; pos <= 42; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 42; pos <= 43; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 43; pos <= 44; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 44; pos <= 45; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 45; pos <= 46; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 46; pos <= 47; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 47; pos <= 48; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 48; pos <= 49; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  for (pos = 49; pos <= 50; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 50; pos <= 51; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 51; pos <= 52; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 52; pos <= 53; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 53; pos <= 54; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 54; pos <= 55; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); //vejrov.cz
  for (pos = 55; pos <= 56; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 56; pos <= 57; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 57; pos <= 58; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 58; pos <= 59; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 59; pos <= 60; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 60; pos <= 61; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 61; pos <= 62; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
   for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
  for (pos = 62; pos <= 63; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 63; pos <= 64; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 64; pos <= 65; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 65; pos <= 66; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 66; pos <= 67; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 67; pos <= 68; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 68; pos <= 69; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 69; pos <= 70; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 70; pos <= 71; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 71; pos <= 72; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 72; pos <= 73; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 73; pos <= 74; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 74; pos <= 75; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red1, fadeValue);
    delay(10);
  } 
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
  for (pos = 75; pos <= 76; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); //vejrov.cz
  for (pos = 76; pos <= 77; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 77; pos <= 78; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 78; pos <= 79; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 79; pos <= 80; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
   for (pos = 80; pos <= 81; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 81; pos <= 82; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 82; pos <= 83; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 83; pos <= 84; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 84; pos <= 85; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 85; pos <= 86; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 86; pos <= 87; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 87; pos <= 88; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 88; pos <= 89; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (pos = 89; pos <= 90; pos +=2){
  servo1.write(pos);   
  value = servo1.read();
  Serial.println(value); }
delay(40); 
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(red2, fadeValue);
    delay(10);
  } 
servo1.detach(); 
delay (5000);}                                                          // zpoždění pro bílé
  wait = false;                                                         // bílé 
     for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(white1, fadeValue);
    delay(30);
  } 
delay(600); 
    for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(white1, fadeValue);
    delay(30);
  }
 for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 255) {
    analogWrite(white2, fadeValue);
    delay(30);
  } 
delay(600); //vejrov.cz
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 255) {
    analogWrite(white2, fadeValue);
    delay(30);
  } 
        }
        }

Funkce viz. video (osazeno do výstražníků):


Funkce viz. video (typ AŽD71):

Dále video typ AŽD97 a SSSR.