mixer-slider/firmware/button.c
2020-11-01 16:23:30 +01:00

32 lines
520 B
C

#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))) {
app.button = !app.button;
led_toggle();
}
}