diff --git a/src/button_poll/button.cpp b/src/button_poll/button.cpp new file mode 100644 index 0000000..11d89d7 --- /dev/null +++ b/src/button_poll/button.cpp @@ -0,0 +1,47 @@ +// +// Created by servostar on 27.10.23. +// + +#include "button.h" + +// --------------------------------------- +// +// DDR set bit of port to either input or output +// PORTx set bit of port value +// PINx read voltage of bit of port D + +#ifdef BUTTON_POLL + +void init() { + // --------------------------------------- + // set Port B to output + // we will write through B5 + SET_OUTPUT(DDRB, DDB5); + CLR_BIT(PORTB, DDB5); + + // --------------------------------------- + // setup input port + // we will read through D2/D3 + + // 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); +} + +void loop() { + + // poll voltage of pin 2 of port D + if (!GET_BIT(PIND, PIND2)) { + SET_BIT(PORTB, DDB5); + } + + // poll voltage of pin 3 of port D + if (!GET_BIT(PIND, PIND3)) { + CLR_BIT(PORTB, DDB5); + } +} + +#endif \ No newline at end of file diff --git a/src/button_poll/button.h b/src/button_poll/button.h new file mode 100644 index 0000000..286d28d --- /dev/null +++ b/src/button_poll/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 ca67b9f..84bbf39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,9 +2,11 @@ extern void init(); extern void loop(); -#include "blink/blink.h" +//#include "blink/blink.h" +#include "button_poll/button.h" -#define BLINK +//#define BLINK +#define BUTTON_POLL int main() { init();