-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (54 loc) · 1.29 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "include/mcu.h"
#include "include/game.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include "peripherals/include/led.h"
#include "peripherals/include/button.h"
#include "peripherals/include/speaker.h"
#include "peripherals/include/rtc.h"
/*
* Setup hardware peripherals
*/
void setup()
{
led_init();
speaker_init();
/* Register handler functions for buttons */
button_init(&button_pressed, &button_released);
/* Register handler function for RTC effects */
rtc_init(&game_led_effect_update);
rtc_set_timeout(LED_EFFECT_TIMEOUT);
sei();
set_sleep_mode(SLEEP_MODE_STANDBY);
}
/*
* Main function called upon reset
*/
int main(void)
{
setup();
while (1) {
/* Put CPU in sleep immediately, awake by button depressing */
sleep_mode();
if(!game_is_running()) {
int start_status = game_is_ready_to_start();
/* Both starting buttons are not pressed */
if (start_status == NOT_READY)
continue;
_delay_ms(BUTTON_START_TIMEOUT);
/* Check if buttons are still pressed after timeout */
if (start_status == game_is_ready_to_start()) {
switch (start_status) {
case READY_EASY:
game_start(EASY);
break;
case READY_HARD:
game_start(HARD);
break;
}
}
}
}
}