stuff
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -5,20 +5,42 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define PLAYER_A_BUTTON 0
|
||||||
|
#define PLAYER_B_BUTTON 1
|
||||||
|
|
||||||
uint32_t ms_since_boot = 0;
|
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)
|
ISR(TIM1_COMPA_vect)
|
||||||
{
|
{
|
||||||
ms_since_boot++;
|
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) {
|
void setupio(void) {
|
||||||
// Set port A to inputs
|
// Set port A to inputs
|
||||||
DDRA = 0x00;
|
DDRA = 0x00;
|
||||||
PORTA |= PORTA0 | PORTA1; // pull-up
|
PORTA |= _BV(PORTA0) | _BV(PORTA1); // pull-up
|
||||||
|
|
||||||
// Set port B0 to output
|
// Set port B to output
|
||||||
DDRB = 0x01;
|
DDRB = 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_clock(void) {
|
void setup_clock(void) {
|
||||||
@@ -39,12 +61,17 @@ int main() {
|
|||||||
sei();
|
sei();
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
uint32_t sec = ms_since_boot / 1000;
|
cli();
|
||||||
if(sec % 2 == 0) {
|
if(button_pressed(PLAYER_A_BUTTON) && player_b_timer != 0) {
|
||||||
PORTB = 1;
|
state = PLAYER_B;
|
||||||
} else {
|
|
||||||
PORTB = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(button_pressed(PLAYER_B_BUTTON) && player_a_timer != 0) {
|
||||||
|
state = PLAYER_A;
|
||||||
|
}
|
||||||
|
|
||||||
|
PORTB = 1 << state;
|
||||||
|
sei();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user