-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputHandler.h
51 lines (38 loc) · 1.01 KB
/
InputHandler.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
/*
* File: InputHandler.h
* Author: Jeff Longo
* Comments: Handles inputs from the pushbutton switches
*/
// Header guard, prevents including this file more than once
#ifndef INPUT_HANDLER_H
#define INPUT_HANDLER_H
#include "Arduino.h"
#include "Direction.h"
#define START 8
#define UP 9
#define DOWN 10
#define LEFT 11
#define RIGHT 12
class InputHandler
{
public:
// Initializes the input handler
InputHandler();
// Initializes runtime variables
void init();
// Checks for a start button press
bool startPressed();
// Polls for input and handles the snake's direction
void update();
// Updates prevDir for the next frame
void saveDir();
// Set the current direction
void setDir(Direction dir) { this->dir = dir; }
// Get the current direction
Direction getDir(){ return dir; }
private:
Direction dir, prevDir, lastButtonPressed;
bool released;
unsigned long timeOfUpRelease, timeOfDownRelease;
};
#endif // INPUT_HANDLER_H