Skip to content

Commit 2f20d7d

Browse files
Update SIK_Circuit_4C-DIYWhoAmI.ino
- Fix minor bug from customer pull request [ #30 ] where the last word in the game is always the same as the first stored element in the `words[]` array - Update comments based on customer's fixes - Extend beep w/ comment from customer's request Co-Authored-By: Francois-Michon <[email protected]>
1 parent ebc5f7b commit 2f20d7d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

SIK_Circuit_4C-DIYWhoAmI/SIK_Circuit_4C-DIYWhoAmI.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ const char* words[arraySize] = {"moose", "beaver", "bear", "goose", "dog", "cat"
3232
"frog", "alligator", "kangaroo", "hippo", "rabbit"
3333
};
3434

35-
int sequence[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //start with an array full of 0s
35+
// the start value in the sequence array must have a value that could never be an index of an array
36+
// or at least a value outside the range of 0 to the size of the words array - 1; in this case, it can't be between 0 to 24
37+
int sequence[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; //start with an array full of -1's
3638

3739
void setup() {
3840

3941
pinMode(buttonPin, INPUT_PULLUP); //set the button pin as an input
4042

4143
lcd.begin(16, 2); //tell the LCD library the size of the screen
4244

43-
generateRandomOrder(); //generate an array of random numbers from 1-25 that will determine which order the words are shown in
45+
generateRandomOrder(); //generate an array of random numbers from 0 to 24 that will determine which order the words are shown in
4446

4547
showStartSequence(); //print the start sequence text
4648

@@ -73,7 +75,7 @@ void loop() {
7375
}
7476

7577
if (digitalRead(buttonPin) == LOW) {
76-
tone(buzzerPin, 272, 1);
78+
tone(buzzerPin, 272, 10); //emit a short beep when the button is pressed
7779
}
7880

7981
} //exit this loop when the button is pressed
@@ -123,14 +125,14 @@ void generateRandomOrder() {
123125

124126
randomSeed(analogRead(0)); //reset the random seed (Arduino needs this to generate truly random numbers
125127

126-
for (int i = 0; i < 24; i++) { //do this until all 25 positions are filled
128+
for (int i = 0; i < arraySize; i++) { //do this until all 25 positions are filled
127129

128130
int currentNumber = 0; //variable to hold the current number
129131
boolean match = false; //does the currentNumber match any of the previous numbers?
130132

131133
//generate random numbers until you've generated one that doesn't match any of the other numbers in the array
132134
do {
133-
currentNumber = random(0, arraySize); //generate a random number from 1-25
135+
currentNumber = random(0, arraySize); //generate a random number from 0 to 24
134136
match = false; //we haven't checked for matches yet, so start by assuming that it doesn't match
135137
for (int i = 0; i < arraySize; i++) { //for all 25 numbers in the array
136138
if (currentNumber == sequence[i]) { //does the currentNumber match any of the numbers?

0 commit comments

Comments
 (0)