#include #define F_CPU 20000000 #include int buttonState = 0; int main(void) { CPU_CCP = CCP_IOREG_gc; // Un-protect protected I/O registers - allow clock changes CLKCTRL_MCLKCTRLB = 0; // disable clock prescaler - clock is now equal to system clock - 20MHz VPORTA_DIR |= PIN7_bm; // set PA7 as ouput (LED) VPORTA_IN |= PIN6_bm; // set PA4 as input (switch) while(1) { buttonState = VPORTA_IN & PIN6_bm; // If button is not pressed if (buttonState > 0) { PORTA_OUTTGL = PIN7_bm; // Toggle PORTA (PA7) _delay_ms(200); // gives delay } } }