#define BUT1              2             //пины (биты D)
#define BUT2              3
#define BUT3              4
#define LED1              5
#define LED2              6
#define LED3              7
           
#define PERIOD1           500           //времена
#define PERIOD2           1000
#define PERIOD3           1500
                                        //i/o
// #define pullup(x)         pinMode(x, INPUT_PULLUP)
// #define pin(x)            (!digitalRead(x))
// #define out(x)            pinMode(x, OUTPUT)
// #define off(x)            digitalWrite(x, LOW)
// #define toggle(x)         digitalWrite(x, !digitalRead(x))
#define pullup(x)         PORTD |= 1<<(x)
#define pin(x)            !(PIND & 1<<(x))
#define out(x)            DDRD |= 1<<(x)
#define off(x)            PORTD &= ~(1<<(x))
#define toggle(x)         PIND = 1<<(x)

#define blink(x,p)        do {                            \
                            static uint16_t t;            \
                            if (++t >= p / 2 && !(t = 0)) \
                              toggle(x);                  \
                          } while (0)


void setup() {
  pullup(BUT1);
  pullup(BUT2);
  pullup(BUT3);
  out(LED1);
  out(LED2);
  out(LED3);
}


void loop() {
  delay(1);
  if (pin(BUT1)) blink(LED1, PERIOD1); else off(LED1);
  if (pin(BUT2)) blink(LED2, PERIOD2); else off(LED2);
  if (pin(BUT3)) blink(LED3, PERIOD3); else off(LED3);
}