This commit is contained in:
2025-12-08 09:14:14 -07:00
parent 4664add5db
commit 79f826176d
2 changed files with 40 additions and 9 deletions
+5 -1
View File
@@ -1,2 +1,6 @@
#define OSCILLATOR_CALIBRATION 0x76
#include <stdint.h>
#define OSCILLATOR_CALIBRATION 0x76
// #define STARTING_TIME_MS (uint32_t)6*60*1000 // 6 min
#define STARTING_TIME_MS (uint32_t)5*1000 // 5 sec
+35 -8
View File
@@ -5,20 +5,42 @@
#include "config.h"
#define PLAYER_A_BUTTON 0
#define PLAYER_B_BUTTON 1
uint32_t ms_since_boot = 0;
typedef enum {
STOPPED,
PLAYER_A,
PLAYER_B
} state_type;
state_type state = STOPPED;
uint32_t player_a_timer = STARTING_TIME_MS;
uint32_t player_b_timer = STARTING_TIME_MS;
ISR(TIM1_COMPA_vect)
{
ms_since_boot++;
if(state == PLAYER_A) {
player_a_timer--;
if(player_a_timer == 0) { state = STOPPED; }
} else if(state == PLAYER_B) {
player_b_timer--;
if(player_b_timer == 0) { state = STOPPED; }
}
}
void setupio(void) {
// Set port A to inputs
DDRA = 0x00;
PORTA |= PORTA0 | PORTA1; // pull-up
PORTA |= _BV(PORTA0) | _BV(PORTA1); // pull-up
// Set port B0 to output
DDRB = 0x01;
// Set port B to output
DDRB = 0xFF;
}
void setup_clock(void) {
@@ -39,12 +61,17 @@ int main() {
sei();
while(true) {
uint32_t sec = ms_since_boot / 1000;
if(sec % 2 == 0) {
PORTB = 1;
} else {
PORTB = 0;
cli();
if(button_pressed(PLAYER_A_BUTTON) && player_b_timer != 0) {
state = PLAYER_B;
}
if(button_pressed(PLAYER_B_BUTTON) && player_a_timer != 0) {
state = PLAYER_A;
}
PORTB = 1 << state;
sei();
}
}