Commit f01457faf637e7bf2dc8f0322fde75920b9a84ee

Authored by Peter M. Groen
1 parent cd268433

Setting up the repo.

SimonSays.ino 0 โ†’ 100644
  1 +void setup() {
  2 + // put your setup code here, to run once:
  3 +
  4 +}
  5 +
  6 +void loop() {
  7 + // put your main code here, to run repeatedly:
  8 +
  9 +}
... ...
game.cpp 0 โ†’ 100644
  1 +#include "game.h"
  2 +
  3 +/* Pin Settings */
  4 +/* Change accordingly for your platform / setup */
  5 +static const int Game::MICROPHONE_PIN = 12;
  6 +static const int Game::BLUE_PIN = 11;
  7 +static const int Game::RED_PIN = 10;
  8 +static const int Game::GREEN_PIN = 09;
  9 +static const int Game::YELLOW_PIN = 08;
  10 +static const int Game::BLUE_BUTTON_PIN = 07;
  11 +static const int Game::RED_BUTTON_PIN = 06;
  12 +static const int Game::GREEN_BUTTON_PIN = 05;
  13 +static const int Game::YELLOW_BUTTON_PIN = 04;
  14 +
  15 +/* Tone Frequencies */
  16 +static const int Game::RED_TONE = 0200;
  17 +static const int Game::BLUE_TONE = 0400;
  18 +static const int Game::YELLOW_TONE = 0600;
  19 +static const int Game::GREEN_TONE = 0800;
  20 +static const int Game::GAMEOVER_TONE = 1000;
  21 +
  22 +Game::Game( int difficulty )
  23 + : gameSpeed( 1000 )
  24 + , lastButtonValue( -1 )
  25 + , currentLevel( 0 )
  26 + , gameDifficulty( difficulty )
  27 + , gameIsOver( 0 )
  28 +{
  29 + initPins();
  30 +}
  31 +
  32 +Game::Game()
  33 + : gameSpeed( 1000 )
  34 + , lastButtonValue( -1 )
  35 + , currentLevel( 0 )
  36 + , gameDifficulty( 10 )
  37 + , gameIsOver( 0 )
  38 +{
  39 + initPins();
  40 +}
  41 +
  42 +void Game::initPins()
  43 +{
  44 + pinMode(Game::MICROPHONE_PIN, OUTPUT);
  45 + pinMode(Game::BLUE_PIN, OUTPUT);
  46 + pinMode(Game::RED_PIN, OUTPUT);
  47 + pinMode(Game::GREEN_PIN, OUTPUT);
  48 + pinMode(Game::YELLOW_PIN, OUTPUT);
  49 +}
  50 +
  51 +int Game::debounce(int last, int buttonPin)
  52 +{
  53 + int current = digitalRead(buttonPin);
  54 + if (last != current)
  55 + {
  56 + delay( 5 );
  57 + current = digitalRead(buttonPin);
  58 + }
  59 +
  60 + return current;
  61 +}
  62 +
  63 +
  64 +
... ...
game.h 0 โ†’ 100644
  1 +#pragma once
  2 +
  3 +class Game
  4 +{
  5 +private:
  6 + int debounce( int last, int buttonPin );
  7 + void playNote( int note, int noteSpeed ) const;
  8 + void flashLed( int led, int flashSpeed ) const;
  9 + void initPins();
  10 +
  11 +public:
  12 + static const int RED_PIN;
  13 + static const int BLUE_PIN;
  14 + static const int GREEN_PIN;
  15 + static const int YELLOW_PIN;
  16 + static const int MICROPHONE_PIN;
  17 + static const int RED_BUTTON_PIN;
  18 + static const int BLUE_BUTTON_PIN;
  19 + static const int GREEN_BUTTON_PIN;
  20 + static const int YELLOW_BUTTON_PIN;
  21 + static const int RED_TONE;
  22 + static const int BLUE_TONE;
  23 + static const int GREEN_TONE;
  24 + static const int YELLOW_TONE;
  25 + static const int GAMEOVER_TONE;
  26 +
  27 + int gameLevel[200];
  28 + int gameSpeed;
  29 + int lastButtonValue;
  30 + int currentLevel;
  31 + int gameIsOver;
  32 + double gameDifficulty;
  33 + enum color { YELLOW, GREEN, RED, BLUE };
  34 +
  35 +public:
  36 + Game();
  37 + Game(int)
  38 + ~Game();
  39 +
  40 + void playLevel();
  41 + int userInput();
  42 + int gameOver();
  43 + int getNote( int note ) const;
  44 + int pinToColorCode( int );
  45 + int colorCodeToPinn( int );
  46 + int readButton( int buttonPin );
  47 +
  48 +};
... ...