28 lines
545 B
C
28 lines
545 B
C
#include "delay.h"
|
|
|
|
int main(void) {
|
|
// PC2 as output (LED), PC3 as input (button)
|
|
timer1_init();
|
|
|
|
DDRB |= (1<<PB2);
|
|
DDRB &= ~(1<<PB3);
|
|
|
|
// enable internal pull-up on PC3 (important)
|
|
PORTB |= (1<<PB3);
|
|
|
|
timer1_init();
|
|
|
|
while(1) {
|
|
// Button pressed -> pin reads LOW because of pull-up
|
|
if (!(PINB & (1<<PB3))) {
|
|
for (int i=0;i<=20;i++){
|
|
PORTB |= (1<<PB2); // LED ON
|
|
delay_ms(200);
|
|
PORTB &= ~(1<<PB2);
|
|
delay_ms(200);
|
|
}
|
|
} else {
|
|
PORTB &= ~(1<<PB2); // LED OFF
|
|
}
|
|
}
|
|
} |