feat: added initial support for user buttons
This commit is contained in:
+100
-1
@@ -11,6 +11,18 @@
|
|||||||
#define SLAVE_FOUR_ADDRESS 0x0B
|
#define SLAVE_FOUR_ADDRESS 0x0B
|
||||||
#define SLAVE_FIVE_ADDRESS 0x0C
|
#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_DATA_PIN 5
|
||||||
#define LED_COUNT 29
|
#define LED_COUNT 29
|
||||||
#define BRIGHTNESS 64
|
#define BRIGHTNESS 64
|
||||||
@@ -24,6 +36,18 @@ const CRGB ERROR_COLOR = CRGB::Red;
|
|||||||
|
|
||||||
void testLedStrip();
|
void testLedStrip();
|
||||||
|
|
||||||
|
void initializeButtonInterrupts();
|
||||||
|
|
||||||
|
void playerOneButtonPressedInterrupt();
|
||||||
|
void playerOneAButtonPressedInterrupt();
|
||||||
|
void playerOneBButtonPressedInterrupt();
|
||||||
|
void playerOneCButtonPressedInterrupt();
|
||||||
|
|
||||||
|
void playerTwoButtonPressedInterrupt();
|
||||||
|
void playerTwoAButtonPressedInterrupt();
|
||||||
|
void playerTwoBButtonPressedInterrupt();
|
||||||
|
void playerTwoCButtonPressedInterrupt();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Wire.begin(SDA_PIN, SCL_PIN);
|
Wire.begin(SDA_PIN, SCL_PIN);
|
||||||
@@ -32,6 +56,10 @@ void setup()
|
|||||||
// Initialize FastLED with the specified LED type, data pin, and LED count
|
// Initialize FastLED with the specified LED type, data pin, and LED count
|
||||||
FastLED.addLeds<LED_TYPE, LED_DATA_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
|
FastLED.addLeds<LED_TYPE, LED_DATA_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
|
||||||
FastLED.setBrightness(BRIGHTNESS);
|
FastLED.setBrightness(BRIGHTNESS);
|
||||||
|
|
||||||
|
// Initialize button interrupts
|
||||||
|
initializeButtonInterrupts();
|
||||||
|
|
||||||
testLedStrip();
|
testLedStrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,4 +81,75 @@ void testLedStrip()
|
|||||||
delay(100); // Wait for a short duration
|
delay(100); // Wait for a short duration
|
||||||
leds[i] = CRGB::Black; // Turn off the LED
|
leds[i] = CRGB::Black; // Turn off the LED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user