|
|
|
@ -16,9 +16,6 @@ |
|
|
|
#define CLK_PIN 52 |
|
|
|
#define CLK_PIN 52 |
|
|
|
#define MAX_DEVICES 9 |
|
|
|
#define MAX_DEVICES 9 |
|
|
|
|
|
|
|
|
|
|
|
#define LONG_PRESS_DURATION 1000 // 1 second for long press
|
|
|
|
|
|
|
|
#define MEMORY_MODE_START_DELAY 1000 // Delay between memory sequence steps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Définitions des pins pour les boutons et les LEDs
|
|
|
|
//Définitions des pins pour les boutons et les LEDs
|
|
|
|
const int player1Buttons[NUM_BUTTONS] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27}; |
|
|
|
const int player1Buttons[NUM_BUTTONS] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27}; |
|
|
|
const int player2Buttons[NUM_BUTTONS] = {45, 47, 49, 35, 37, 39, 41, 43, 29, 31, 33}; |
|
|
|
const int player2Buttons[NUM_BUTTONS] = {45, 47, 49, 35, 37, 39, 41, 43, 29, 31, 33}; |
|
|
|
@ -43,13 +40,6 @@ unsigned long lastDebounceTime2[NUM_BUTTONS] = {0}; |
|
|
|
|
|
|
|
|
|
|
|
bool testMode = false; |
|
|
|
bool testMode = false; |
|
|
|
|
|
|
|
|
|
|
|
int gameMode = 1; // Default to mode 1
|
|
|
|
|
|
|
|
bool modeSelected = false; |
|
|
|
|
|
|
|
int memorySequence[NUM_BUTTONS * 2] = {0}; |
|
|
|
|
|
|
|
int memorySequenceLength = 3; |
|
|
|
|
|
|
|
int memorySequenceIndex = 0; |
|
|
|
|
|
|
|
bool memoryInputActive = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void waitForStartButton() { |
|
|
|
void waitForStartButton() { |
|
|
|
digitalWrite(startLEDPin, HIGH); // Turn on the start LED
|
|
|
|
digitalWrite(startLEDPin, HIGH); // Turn on the start LED
|
|
|
|
while (digitalRead(startButtonPin) == HIGH) { |
|
|
|
while (digitalRead(startButtonPin) == HIGH) { |
|
|
|
@ -221,69 +211,6 @@ void displayMotif(const boolean motif[],int size, int dt) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Function to display the current mode on the timer display
|
|
|
|
|
|
|
|
void displayMode(int mode) { |
|
|
|
|
|
|
|
myDisplay.displayReset(); |
|
|
|
|
|
|
|
String modeStr = "MOD" + String(mode); |
|
|
|
|
|
|
|
myDisplay.displayZoneText(2, modeStr.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); |
|
|
|
|
|
|
|
myDisplay.displayAnimate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to generate a new memory sequence
|
|
|
|
|
|
|
|
void generateMemorySequence() { |
|
|
|
|
|
|
|
for (int i = 0; i < memorySequenceLength; i++) { |
|
|
|
|
|
|
|
memorySequence[i] = random(NUM_BUTTONS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to display the memory sequence
|
|
|
|
|
|
|
|
void displayMemorySequence() { |
|
|
|
|
|
|
|
for (int i = 0; i < memorySequenceLength; i++) { |
|
|
|
|
|
|
|
digitalWrite(player1LEDs[memorySequence[i]], HIGH); |
|
|
|
|
|
|
|
delay(MEMORY_MODE_START_DELAY); |
|
|
|
|
|
|
|
digitalWrite(player1LEDs[memorySequence[i]], LOW); |
|
|
|
|
|
|
|
delay(MEMORY_MODE_START_DELAY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
memoryInputActive = true; |
|
|
|
|
|
|
|
memorySequenceIndex = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to check player input in memory mode
|
|
|
|
|
|
|
|
void checkMemoryInput() { |
|
|
|
|
|
|
|
for (int i = 0; i < NUM_BUTTONS; i++) { |
|
|
|
|
|
|
|
if (digitalRead(player1Buttons[i]) == LOW) { |
|
|
|
|
|
|
|
delay(DEFAULT_DEBOUNCE_DELAY); // Debounce delay
|
|
|
|
|
|
|
|
if (i == memorySequence[memorySequenceIndex]) { |
|
|
|
|
|
|
|
memorySequenceIndex++; |
|
|
|
|
|
|
|
if (memorySequenceIndex == memorySequenceLength) { |
|
|
|
|
|
|
|
player1Score += memorySequenceLength; |
|
|
|
|
|
|
|
memorySequenceLength++; |
|
|
|
|
|
|
|
generateMemorySequence(); |
|
|
|
|
|
|
|
displayMemorySequence(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
player1Score = max(0, player1Score - 1); |
|
|
|
|
|
|
|
generateMemorySequence(); |
|
|
|
|
|
|
|
displayMemorySequence(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to handle mode selection
|
|
|
|
|
|
|
|
void selectGameMode() { |
|
|
|
|
|
|
|
unsigned long pressStartTime = millis(); |
|
|
|
|
|
|
|
while (digitalRead(startButtonPin) == LOW) { |
|
|
|
|
|
|
|
if (millis() - pressStartTime > LONG_PRESS_DURATION) { |
|
|
|
|
|
|
|
modeSelected = true; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gameMode = (gameMode == 1) ? 2 : 1; |
|
|
|
|
|
|
|
displayMode(gameMode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
void setup() { |
|
|
|
for (int i = 0; i < NUM_BUTTONS; i++) { |
|
|
|
for (int i = 0; i < NUM_BUTTONS; i++) { |
|
|
|
pinMode(player1Buttons[i], INPUT_PULLUP); |
|
|
|
pinMode(player1Buttons[i], INPUT_PULLUP); |
|
|
|
@ -316,21 +243,10 @@ void setup() { |
|
|
|
testMode = true; |
|
|
|
testMode = true; |
|
|
|
displayTestMode(); |
|
|
|
displayTestMode(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
while (!modeSelected) { |
|
|
|
displayMotif(motif1, 242, 150); |
|
|
|
if (digitalRead(startButtonPin) == LOW) { |
|
|
|
waitForStartButton(); |
|
|
|
selectGameMode(); |
|
|
|
startTime = millis(); |
|
|
|
} |
|
|
|
initializeLEDs(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gameMode == 2) { |
|
|
|
|
|
|
|
generateMemorySequence(); |
|
|
|
|
|
|
|
displayMemorySequence(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
displayMotif(motif1, 242, 150); |
|
|
|
|
|
|
|
waitForStartButton(); |
|
|
|
|
|
|
|
startTime = millis(); |
|
|
|
|
|
|
|
initializeLEDs(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -340,17 +256,12 @@ void loop() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (gameMode == 1) { |
|
|
|
unsigned long currentTime = millis(); |
|
|
|
unsigned long currentTime = millis(); |
|
|
|
if (currentTime - startTime >= GAME_DURATION) { |
|
|
|
if (currentTime - startTime >= GAME_DURATION) { |
|
|
|
endGame(); |
|
|
|
endGame(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateDisplays(currentTime); |
|
|
|
|
|
|
|
checkButtons(); |
|
|
|
|
|
|
|
} else if (gameMode == 2) { |
|
|
|
|
|
|
|
if (memoryInputActive) { |
|
|
|
|
|
|
|
checkMemoryInput(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateDisplays(currentTime); |
|
|
|
|
|
|
|
checkButtons(); |
|
|
|
} |
|
|
|
} |