27 lines
507 B
C
27 lines
507 B
C
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#define LED_PORT PORTB0
|
|
#define BTN_PORT PIND2
|
|
|
|
int main(void) {
|
|
// set pin to output
|
|
DDRB |= (_BV(LED_PORT));
|
|
|
|
bool led_state = false;
|
|
bool prev = (PIND & _BV(BTN_PORT));
|
|
while (true) {
|
|
bool cur = (PIND & _BV(BTN_PORT));
|
|
if (prev && !cur) {
|
|
led_state = !led_state;
|
|
if (led_state)
|
|
PORTB |= (_BV(LED_PORT));
|
|
else
|
|
PORTB &= ~(_BV(LED_PORT));
|
|
}
|
|
prev = cur;
|
|
_delay_ms(20.f);
|
|
}
|
|
}
|