Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f28335

Browse files
committed
Added some constants. Will be keeping some "hard-coded" values as it makes sense where they are.
1 parent e212429 commit 6f28335

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

‎Arduino-Says.ino‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "LinkedList.h"
22

3+
#define DEFAULT_BAUD 9600
34
#define N_LEDS 4
45
#define N_LIVES 3
5-
#define INPUT_DELAY 200
6+
#define INPUT_DELAY 150
7+
#define NO_INPUT -1
68

79
int leds[N_LEDS] = {5, 4, 3, 2};
810
int buttons[N_LEDS] = {6, 7, 8, 9};
@@ -23,7 +25,7 @@ void setup() {
2325
}
2426
pinMode(buzzer, OUTPUT);
2527
noTone(buzzer);
26-
Serial.begin(9600);
28+
Serial.begin(DEFAULT_BAUD);
2729
randomSeed(analogRead(0));
2830
gameSetup();
2931
}
@@ -49,7 +51,7 @@ void waitForStart() {
4951
tone(buzzer, buzzerScale[random(N_LEDS)]);
5052
Serial.println("Press any button.");
5153
//Flash leds and check for any button to be pressed.
52-
while (checkInputArray(buttons, N_LEDS) == -1) {
54+
while (checkInputArray(buttons, N_LEDS) == NO_INPUT) {
5355
currMillis = millis();
5456
// if leds are on (only need to check 1).
5557
if (digitalRead(leds[0])) {
@@ -78,8 +80,9 @@ void waitForStart() {
7880
void playGame() {
7981
int score = 0;
8082
int lives = N_LIVES;
81-
const int startStepDelay = 500;
82-
const int minDelay = 100;
83+
const int minDelay = 80;
84+
const int diffSteepness = 450;
85+
int startStepDelay = minDelay + diffSteepness;
8386
int stepDelay = startStepDelay;
8487
int choice;
8588
bool rightAnswer;
@@ -107,7 +110,7 @@ void playGame() {
107110
if (rightAnswer) {
108111
score++;
109112
displayRightAnswer(score);
110-
stepDelay = startStepDelay/(score+1) + minDelay;
113+
stepDelay = diffSteepness/(score+1) + minDelay;
111114
generateRandomSequence(gameSequence);
112115
} else {
113116
lives--;
@@ -122,8 +125,8 @@ void playGame() {
122125

123126
//Waits for player input and returns the pin of the clicked button.
124127
int waitForPlay() {
125-
int choice = -1;
126-
while (choice == -1) {
128+
int choice = NO_INPUT;
129+
while (choice == NO_INPUT) {
127130
choice = checkInputArray(buttons, N_LEDS);
128131
}
129132

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /