#include #include int main() { //setup // Button on PB2 // LED on PA3 // LED on PA7 PORTB = _BV(PB2); // set B2 pull up on (default is input) DDRA = _BV(PA3) | _BV(PA7); // set A3 and A7 as output for LED char lightOn = 0; //Loop while (TRUE) { // check if button is pressed if(bit_is_clear(PINB,PB2)) { // wait until the button is let go while(bit_is_clear(PINB, PB2)) { lightOn = lightOn; } // alternate between the two light on and light off states if(lightOn == 0) { lightOn = 1; } else { lightOn = 0; } } if(lightOn == 0) { PORTA |= _BV(PA3) | _BV(PA7); } else if (lightOn == 1) { PORTA = 0; } //delay for debouncing //wait 50 ms between successive switches so that one button press is not accidentally read as multiple presses _delay_ms(50); } }