forked from calidae/futbolino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
futbolino.h
81 lines (63 loc) · 1.45 KB
/
futbolino.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _FUTBOLINO_H
#define _FUTBOLINO_H
#include <MD_Parola.h>
#include <my_structs.h>
#define _FUTBOLINO_H_DEBUG
#ifdef _FUTBOLINO_H_DEBUG
#define DEBUG(A) Serial.println(A)
#else
#define DEBUG(A)
#endif
#define SCREEN_BUF_SIZE 75
const int IR_THRESHOLD = 300;
enum GameState
{
SERVE,
PLAY,
WIN
};
enum Team
{
UNDEFINED,
A,
B
};
const char TXT_WIN[] = "TEAM A WINS! YEAH!";
const char TXT_SERVE[] = "Saque";
const char TXT_CONGRATS[] = "Enhorabona";
const char TXT_CALM_SERVE[] = "Tranqui, és pel saque";
class Futbolino {
public:
Futbolino(Inputs in, MD_Parola *screen);
void begin();
void loop();
private:
Inputs _in;
MD_Parola* _screen;
char _screenBufferA[SCREEN_BUF_SIZE];
char _screenBufferB[SCREEN_BUF_SIZE];
GameState _currentState;
Team _lastScored;
bool _breakAnimation = false;
int _golsA = 0;
int _golsB = 0;
bool _debounceIrA = false;
bool _debounceIrB = false;
bool _debounceButtonPlusA = false;
bool _debounceButtonMinusA = false;
bool _debounceButtonPlusB = false;
bool _debounceButtonMinusB = false;
void addGoal(int &team, int delta = 1);
void readButton(int &ir, bool &debounce);
struct Buttons readButtons();
void chooseServerTeam(Sensors s, Buttons b);
void updateScore(Buttons b);
struct Sensors readIRSensors();
void updateScore(Sensors s);
bool checkDebounce(bool &input, bool &debounce);
bool areAllButtonsPressed(Buttons b);
void resetScore();
void manageStates();
void updateScreen();
};
#endif