Added simple functions for checking button status

This commit is contained in:
Andrew Lalis 2022-12-08 08:28:32 +01:00
parent 24981c493e
commit e8492a8caa
3 changed files with 18 additions and 3 deletions

View File

@ -3,8 +3,13 @@ all: clean build
clean: clean:
rm -rf bin/ rm -rf bin/
# The following settings are very important!
# -c arduino for flashing to an AVR device with arduino bootloader.
# -p atmega328p is for the specific microcontroller.
# -b 57600 is the baudrate for transmission. Nano boards ONLY accept 57600, uno boards might accept 115200.
# -P specifies the port.
flash: build flash: build
avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -b115200 -U flash:w:bin/gympal.hex:i avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -b 57600 -U flash:w:bin/gympal.hex:i
build: gympal.hex build: gympal.hex

View File

@ -40,6 +40,16 @@ void ctl_init();
* @brief Determines if button A has been pressed. * @brief Determines if button A has been pressed.
* @return uint8_t 1 if pressed, 0 otherwise. * @return uint8_t 1 if pressed, 0 otherwise.
*/ */
uint8_t ctl_isButtonAPressed(); inline uint8_t ctl_isButtonAPressed() {
return (CTL_INPUT_FLAGS & (1 << CTL_BUTTON_A_FLAG)) >> CTL_BUTTON_A_FLAG;
}
inline uint8_t ctl_isButtonBPressed() {
return (CTL_INPUT_FLAGS & (1 << CTL_BUTTON_B_FLAG)) >> CTL_BUTTON_B_FLAG;
}
inline uint8_t ctl_isButtonCPressed() {
return (CTL_INPUT_FLAGS & (1 << CTL_BUTTON_C_FLAG)) >> CTL_BUTTON_C_FLAG;
}
#endif #endif

View File

@ -10,7 +10,7 @@ int main() {
PORTB &= ~(1 << PORTB4); PORTB &= ~(1 << PORTB4);
uint8_t led = 0; uint8_t led = 0;
while(1) { while(1) {
uint8_t v = (CTL_INPUT_FLAGS & (1 << CTL_BUTTON_B_FLAG)) >> CTL_BUTTON_A_FLAG; uint8_t v = ctl_isButtonAPressed();
if (led != v) { if (led != v) {
led = v; led = v;
if (led) { if (led) {