Arduino pure c programming part2 push button
/* Toggle a on-board led if push button is pressed */ #include <avr/io.h> void init_io() { DDRB |= 1<<PB5; //Setting the pin as output DDRD &= ~(1<<PD2); //Setting the pin as input } int is_button_pressed() { return (PIND&(1<<PD2)) ; } void toggle_led() { PORTB ^= 1<<PB5; } int main() { init_io(); while(1){ if(is_button_pressed()) toggle_led(); } return 0; }