int num;
bool oneClick = true;
void setup(){
Serial.begin(9600);
DDRB = 0b00000111;
PORTD |= 1<<7;
PORTD |= 1<<5;
}
void loop(){
Serial.println(num);
// switch
if( (PIND &(1<<5)) == 0){
PORTB = 0b00000000;
return;
}
// button
if(oneClick == true && (PIND &(1<<7)) == 0){
oneClick = false;
num++;
}
// off
if(num % 2 == 1){
PORTB = 0b00000000;
}
// on
if(num % 2 == 0){
if( (PIND &(1<<6)) == 0){
PORTB &= ~(1<<0);
PORTB |= 1<<1;
PORTB &= ~(1<<2);
}
if( (PIND &(1<<6)) != 0){
PORTB &= ~(1<<1);
PORTB |= 1<<2;
}
}
if(oneClick != true && (PIND &(1<<7)) != 0) oneClick = true;
}