2019-02-10 19:12:40 +01:00
|
|
|
#include "button.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "led.h"
|
|
|
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
|
|
|
void button_init()
|
|
|
|
{
|
|
|
|
led_init();
|
|
|
|
|
|
|
|
// enable pullup on button pin
|
|
|
|
BUTTON_DDR &= ~(1<<BUTTON_PIN);
|
|
|
|
BUTTON_PORT |= (1<<BUTTON_PIN);
|
|
|
|
|
|
|
|
// activate pin change interrupt
|
|
|
|
// PCINT9
|
|
|
|
PCMSK1 |= (1<<PCINT9);
|
|
|
|
GIMSK |= (1<<PCIE1); // enable PCINT1
|
|
|
|
}
|
|
|
|
|
|
|
|
button_state_t button_is_pressed()
|
|
|
|
{
|
|
|
|
return (BUTTON_REG&(1<<BUTTON_PIN)) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISR(PCINT1_vect) {
|
|
|
|
if(!(BUTTON_REG&(1<<BUTTON_PIN))) {
|
2019-02-13 15:18:38 +01:00
|
|
|
app.button = !app.button;
|
2019-02-10 19:12:40 +01:00
|
|
|
led_toggle();
|
|
|
|
}
|
|
|
|
}
|