#include <Servo.h>
Servo myservo;
unsigned long int future = 0;
int stav = 0;

void setup() {
  DDRB &=~(1<<0);   
  DDRB &=~(1<<1);
  DDRB &=~(1<<3); 
  DDRB &=~(1<<4); 
  myservo.attach(3);
  myservo.write(90);

  DDRD |=1<<4;
  DDRD |=1<<5;
  DDRD |=1<<6;
  PORTD |=1<<4;
  PORTD |=1<<5;
  PORTD |=1<<6;

  future = millis();

}

void loop() {
  if( ((PINB&(1<<0)) != 0) && (PINB&(1<<1)) == 0){
  myservo.write(180);
}else if( ((PINB&(1<<0)) == 0)  && ((PINB&(1<<1)) != 0) ){
  myservo.write(0);
}else if( (((PINB&(1<<0)) == 0)  && ((PINB&(1<<1)) == 0)) || 
(((PINB&(1<<0)) != 0)  && ((PINB&(1<<1)) != 0)) ){
  myservo.write(90);
}


if(millis() > future) 
 {
   if( ((PINB&(1<<2)) != 0) && (PINB&(1<<3)) == 0){
    stav++; // kod, ktory sa vykona raz za pol sekundy
     if(stav == 2)
    stav = 0;
    }else if( (((PINB&(1<<2)) == 0)  && ((PINB&(1<<3)) == 0)) || 
(((PINB&(1<<2)) != 0)  && ((PINB&(1<<3)) != 0)) ){
    stav = 1;
    }
    else if( ((PINB&(1<<2)) == 0) && (PINB&(1<<3)) != 0){
    stav++;
    if(stav == 4)
    stav = 2;
    }
    future = millis() + 500;
 }

switch(stav) 
 {
 case 0: (PORTD &=~(1<<4));  break; 
 case 1: (PORTD |=1<<4); (PORTD |=1<<5); (PORTD |=1<<6); break; 
 case 2: (PORTD &=~(1<<4)); (PORTD &=~(1<<5)); (PORTD &=~(1<<6)); break; 
 case 3: (PORTD |=1<<4); (PORTD |=1<<5); (PORTD |=1<<6); break; 
 default: break; 
 }

}