diff --git a/src/button_interupt/button.cpp b/src/button_interupt/button.cpp new file mode 100644 index 0000000..f32fa2a --- /dev/null +++ b/src/button_interupt/button.cpp @@ -0,0 +1,47 @@ +// +// Created by servostar on 27.10.23. +// + +#include "button.h" + +#ifdef BUTTON_INTERRUPT + +ISR(INT0_vect) +{ + PORTB = 0; +} + +ISR(INT1_vect) +{ + PORTB = 0xff; +} + +void init() { + // set B as output + DDRB = 0xff; + PORTB = 0x00; + + // set Port D to input (bit 2/3, remember bit 0/1 are for UART) + SET_INPUT(DDRD, DDD2); + SET_INPUT(DDRD, DDD3); + // put 5V on input (make it pull up resistor) + SET_BIT(PORTD, DDD2); + SET_BIT(PORTD, DDD3); + + // configure interrupt mode + SET_INTERRUPT_MODE(0, FALLING); + SET_INTERRUPT_MODE(1, FALLING); + + // enable interrupt 0 and 1 + ENABLE_INTERRUPT(0); + ENABLE_INTERRUPT(1); + + // enable interrupts globally + sei(); +} + +void loop() { + +} + +#endif \ No newline at end of file diff --git a/src/button_interupt/button.h b/src/button_interupt/button.h new file mode 100644 index 0000000..286d28d --- /dev/null +++ b/src/button_interupt/button.h @@ -0,0 +1,13 @@ +// +// Created by servostar on 27.10.23. +// + +#ifndef ARDUINO_BUTTON_H +#define ARDUINO_BUTTON_H + +#include "prelude.h" + +void init(); +void loop(); + +#endif //ARDUINO_BUTTON_H diff --git a/src/main.cpp b/src/main.cpp index 84bbf39..0001e4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,10 +3,12 @@ extern void init(); extern void loop(); //#include "blink/blink.h" -#include "button_poll/button.h" +//#include "button_poll/button.h" +#include "button_interupt/button.h" //#define BLINK -#define BUTTON_POLL +//#define BUTTON_POLL +#define BUTTON_INTERRUPT int main() { init();