WIP: implement device logic for game #1

Draft
k.pietrak wants to merge 7 commits from feature/add-main-functionalities into develop
Showing only changes of commit 8f84e04f0b - Show all commits
+100 -1
View File
@@ -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<LED_TYPE, LED_DATA_PIN, COLOR_ORDER>(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
}
}
}
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");
}