-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.h
More file actions
71 lines (57 loc) · 1.18 KB
/
player.h
File metadata and controls
71 lines (57 loc) · 1.18 KB
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
#ifndef PLAYER_H
#define PLAYER_H
#include <SparkFun_TB6612.h>
#include <Bounce2.h>
const int DEBOUNCE_TIME = 25;
const int HIT_RESET_TIME = 1000;
const int ACCELERATION_FACTOR = 10;
const int FRICTION = 70;
class Player {
public:
enum PlayerState {
offmark,
onmark,
started,
halfway,
finished
};
const char* stateNames[5] = {"offmark","onmark","started","halfway","finished"};
Player();
Player(int top, int bottom, int out, int up, int down, Motor* motor);
void update();
const char* getState();
bool isOnMark();
bool isFinished();
void setOut(bool value);
void setControls(bool enabled);
void stopMotors();
void reset();
void upPressed();
void downPressed();
String ID;
private:
//Pins
int topStopPin;
int bottomStopPin;
int outPin;
int upButtonPin;
int downButtonPin;
//Motor and controls
Motor* motor;
int currentSpeed;
bool controlsEnabled;
int upHits;
int downHits;
Bounce up;
Bounce down;
struct Timer {
unsigned long start;
unsigned long duration;
} hitTimer;
//State
PlayerState state, previousState;
void initialize(bool pinsSet = true);
void move(int newSpeed);
void move();
};
#endif