From 8f84e04f0bad5e1c64e7c5db5da56c3287c01b3a Mon Sep 17 00:00:00 2001 From: SWETRAK Date: Sat, 4 Jul 2026 10:11:18 +0200 Subject: [PATCH] feat: added initial support for user buttons --- APL_Master/src/main.cpp | 101 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/APL_Master/src/main.cpp b/APL_Master/src/main.cpp index 3ff2a1f..f7bb204 100644 --- a/APL_Master/src/main.cpp +++ b/APL_Master/src/main.cpp @@ -11,6 +11,18 @@ #define SLAVE_FOUR_ADDRESS 0x0B #define SLAVE_FIVE_ADDRESS 0x0C +// Buttons pins +#define PLAYER_ONE_BUTTON_PIN 32 +#define PLAYER_ONE_A_BUTTON_PIN 33 +#define PLAYER_ONE_B_BUTTON_PIN 25 +#define PLAYER_ONE_C_BUTTON_PIN 26 + +#define PLAYER_TWO_BUTTON_PIN 27 +#define PLAYER_TWO_A_BUTTON_PIN 14 +#define PLAYER_TWO_B_BUTTON_PIN 12 +#define PLAYER_TWO_C_BUTTON_PIN 13 + +// LEDs pins and configuration #define LED_DATA_PIN 5 #define LED_COUNT 29 #define BRIGHTNESS 64 @@ -24,6 +36,18 @@ const CRGB ERROR_COLOR = CRGB::Red; void testLedStrip(); +void initializeButtonInterrupts(); + +void playerOneButtonPressedInterrupt(); +void playerOneAButtonPressedInterrupt(); +void playerOneBButtonPressedInterrupt(); +void playerOneCButtonPressedInterrupt(); + +void playerTwoButtonPressedInterrupt(); +void playerTwoAButtonPressedInterrupt(); +void playerTwoBButtonPressedInterrupt(); +void playerTwoCButtonPressedInterrupt(); + void setup() { Wire.begin(SDA_PIN, SCL_PIN); @@ -32,6 +56,10 @@ void setup() // Initialize FastLED with the specified LED type, data pin, and LED count FastLED.addLeds(leds, LED_COUNT).setCorrection(TypicalLEDStrip); FastLED.setBrightness(BRIGHTNESS); + + // Initialize button interrupts + initializeButtonInterrupts(); + testLedStrip(); } @@ -53,4 +81,75 @@ void testLedStrip() delay(100); // Wait for a short duration leds[i] = CRGB::Black; // Turn off the LED } -} \ No newline at end of file +} + +void initializeButtonInterrupts() +{ + pinMode(PLAYER_ONE_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_A_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_B_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_ONE_C_BUTTON_PIN, INPUT_PULLUP); + + pinMode(PLAYER_TWO_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_A_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_B_BUTTON_PIN, INPUT_PULLUP); + pinMode(PLAYER_TWO_C_BUTTON_PIN, INPUT_PULLUP); + + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_BUTTON_PIN), playerOneButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_A_BUTTON_PIN), playerOneAButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_B_BUTTON_PIN), playerOneBButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_ONE_C_BUTTON_PIN), playerOneCButtonPressedInterrupt, FALLING); + + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_BUTTON_PIN), playerTwoButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_A_BUTTON_PIN), playerTwoAButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_B_BUTTON_PIN), playerTwoBButtonPressedInterrupt, FALLING); + attachInterrupt(digitalPinToInterrupt(PLAYER_TWO_C_BUTTON_PIN), playerTwoCButtonPressedInterrupt, FALLING); +} + +void playerOneButtonPressedInterrupt() +{ + // Handle Player One button press interrupt + Serial.println("Player One button pressed"); +} + +void playerOneAButtonPressedInterrupt() +{ + // Handle Player One A button press interrupt + Serial.println("Player One A button pressed"); +} + +void playerOneBButtonPressedInterrupt() +{ + // Handle Player One B button press interrupt + Serial.println("Player One B button pressed"); +} + +void playerOneCButtonPressedInterrupt() +{ + // Handle Player One C button press interrupt + Serial.println("Player One C button pressed"); +} + +void playerTwoButtonPressedInterrupt() +{ + // Handle Player Two button press interrupt + Serial.println("Player Two button pressed"); +} + +void playerTwoAButtonPressedInterrupt() +{ + // Handle Player Two A button press interrupt + Serial.println("Player Two A button pressed"); +} + +void playerTwoBButtonPressedInterrupt() +{ + // Handle Player Two B button press interrupt + Serial.println("Player Two B button pressed"); +} + +void playerTwoCButtonPressedInterrupt() +{ + // Handle Player Two C button press interrupt + Serial.println("Player Two C button pressed"); +}