game.cpp
1.56 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
#include "game.h"
/* Pin Settings */
/* Change accordingly for your platform / setup */
static const int Game::MICROPHONE_PIN = 12;
static const int Game::BLUE_PIN = 11;
static const int Game::RED_PIN = 10;
static const int Game::GREEN_PIN = 09;
static const int Game::YELLOW_PIN = 08;
static const int Game::BLUE_BUTTON_PIN = 07;
static const int Game::RED_BUTTON_PIN = 06;
static const int Game::GREEN_BUTTON_PIN = 05;
static const int Game::YELLOW_BUTTON_PIN = 04;
/* Tone Frequencies */
static const int Game::RED_TONE = 0200;
static const int Game::BLUE_TONE = 0400;
static const int Game::YELLOW_TONE = 0600;
static const int Game::GREEN_TONE = 0800;
static const int Game::GAMEOVER_TONE = 1000;
Game::Game( int difficulty )
: gameSpeed( 1000 )
, lastButtonValue( -1 )
, currentLevel( 0 )
, gameDifficulty( difficulty )
, gameIsOver( 0 )
{
initPins();
}
Game::Game()
: gameSpeed( 1000 )
, lastButtonValue( -1 )
, currentLevel( 0 )
, gameDifficulty( 10 )
, gameIsOver( 0 )
{
initPins();
}
void Game::initPins()
{
pinMode(Game::MICROPHONE_PIN, OUTPUT);
pinMode(Game::BLUE_PIN, OUTPUT);
pinMode(Game::RED_PIN, OUTPUT);
pinMode(Game::GREEN_PIN, OUTPUT);
pinMode(Game::YELLOW_PIN, OUTPUT);
}
int Game::debounce(int last, int buttonPin)
{
int current = digitalRead(buttonPin);
if (last != current)
{
delay( 5 );
current = digitalRead(buttonPin);
}
return current;
}