Untitled
unknown
plain_text
a year ago
1.4 kB
5
Indexable
#include <stdio.h>
#include <time.h> // Placeholder, you'll need hardware-specific timers
#include "buttons.h"
#include "lcd.h"
#define MAX_TIME 300 // 5 minutes in seconds
int player1Time = MAX_TIME;
int player2Time = MAX_TIME;
bool player1Turn = true; // Start with player 1
void updateDisplay() {
LCD_ClearScreen();
LCD_PutString("Player 1: ", 7);
LCD_PutString(player1Time / 60); // Minutes
LCD_PutChar(':');
LCD_PutString((player1Time % 60) < 10 ? "0" : ""); // Leading zero
LCD_PutString(player1Time % 60);
// ... (similar code for Player 2) ...
}
void decrementTimer() {
if (player1Turn) {
player1Time--;
if (player1Time == 0) {
LCD_ClearScreen();
LCD_PutString("Player 1 Loses!");
}
} else {
// ... (similar for player 2) ...
}
updateDisplay();
}
int main() {
LCD_Initialize();
BUTTON_Enable(BUTTON_S3); // Assuming buttons are defined
BUTTON_Enable(BUTTON_S6);
updateDisplay();
while (true) {
if (BUTTON_IsPressed(BUTTON_S3)) {
player1Turn = false;
} else if (BUTTON_IsPressed(BUTTON_S6)) {
player1Turn = true;
}
// Simulate timer decrement (replace with real timer)
for (int i = 0; i < 100000; i++); // Crude 1-second-ish delay
decrementTimer();
}
return 0;
}
Editor is loading...
Leave a Comment