From f01457faf637e7bf2dc8f0322fde75920b9a84ee Mon Sep 17 00:00:00 2001 From: Peter M. Groen Date: Mon, 28 Nov 2022 07:06:32 +0100 Subject: [PATCH] Setting up the repo. --- SimonSays.ino | 9 +++++++++ game.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ game.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 0 deletions(-) create mode 100644 SimonSays.ino create mode 100644 game.cpp create mode 100644 game.h diff --git a/SimonSays.ino b/SimonSays.ino new file mode 100644 index 0000000..95c2b6e --- /dev/null +++ b/SimonSays.ino @@ -0,0 +1,9 @@ +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/game.cpp b/game.cpp new file mode 100644 index 0000000..da8f03e --- /dev/null +++ b/game.cpp @@ -0,0 +1,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; +} + + + diff --git a/game.h b/game.h new file mode 100644 index 0000000..4fa9e40 --- /dev/null +++ b/game.h @@ -0,0 +1,48 @@ +#pragma once + +class Game +{ +private: + int debounce( int last, int buttonPin ); + void playNote( int note, int noteSpeed ) const; + void flashLed( int led, int flashSpeed ) const; + void initPins(); + +public: + static const int RED_PIN; + static const int BLUE_PIN; + static const int GREEN_PIN; + static const int YELLOW_PIN; + static const int MICROPHONE_PIN; + static const int RED_BUTTON_PIN; + static const int BLUE_BUTTON_PIN; + static const int GREEN_BUTTON_PIN; + static const int YELLOW_BUTTON_PIN; + static const int RED_TONE; + static const int BLUE_TONE; + static const int GREEN_TONE; + static const int YELLOW_TONE; + static const int GAMEOVER_TONE; + + int gameLevel[200]; + int gameSpeed; + int lastButtonValue; + int currentLevel; + int gameIsOver; + double gameDifficulty; + enum color { YELLOW, GREEN, RED, BLUE }; + +public: + Game(); + Game(int) + ~Game(); + + void playLevel(); + int userInput(); + int gameOver(); + int getNote( int note ) const; + int pinToColorCode( int ); + int colorCodeToPinn( int ); + int readButton( int buttonPin ); + +}; -- libgit2 0.21.4