/*
  Elektomagneticke delo
*/

#define LED   3
#define RELE  7
#define L1    8
#define L2    9
#define L3    10
#define L4    11
#define L5    12

int n;

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(LED, OUTPUT);     
  pinMode(RELE, OUTPUT);     
  pinMode(L1, OUTPUT);     
  pinMode(L2, OUTPUT);     
  pinMode(L3, OUTPUT);     
  pinMode(L4, OUTPUT);     
  pinMode(L5, OUTPUT);     
  digitalWrite(LED, HIGH);   
  digitalWrite(RELE, HIGH);   
  digitalWrite(L1, HIGH);   
  digitalWrite(L2, HIGH);   
  digitalWrite(L3, HIGH);   
  digitalWrite(L4, HIGH);   
  digitalWrite(L5, HIGH);   
  Serial.begin(9600);  
}

void loop() {


  Serial.println("Cekam...");                  
  while (Serial.available() == 0)
  {
    digitalWrite(LED, LOW);  
    delay(100);
    digitalWrite(LED, HIGH);  
    delay(100);
  }
  digitalWrite(LED, HIGH);  
  
  if( Serial.read()=='g')
  {
    Serial.println("Nabijim...");                  
    digitalWrite(RELE, LOW);  
    for(n=0;n<9;n++)
    {
      delay(10000);
      Serial.print(n+1, HEX);
      Serial.println(".");                  
    }  
    digitalWrite(RELE, HIGH);  
    Serial.println("Nabito.");                  
    digitalWrite(LED, LOW);  
    delay(1000);
    Serial.println("Pal.");                  
    digitalWrite(LED, HIGH);  
    digitalWrite(RELE, HIGH);  
    digitalWrite(L1, LOW);  
    delayMicroseconds(1000);
    digitalWrite(L2, LOW);  
    delayMicroseconds(100);
    digitalWrite(L3, LOW);  
    delay(1000);
    digitalWrite(L4, LOW);  
    delay(100);
    digitalWrite(L5, LOW);  
    delay(100);
    digitalWrite(L1, HIGH);  
    digitalWrite(L2, HIGH);  
    digitalWrite(L3, HIGH);  
    digitalWrite(L4, HIGH);  
    digitalWrite(L5, HIGH);  
    Serial.println("Jak to dopadlo?");                  
  }
}