diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2014-08-14 08:31:17 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2014-08-14 08:44:54 -0700 |
commit | 664a207a42d0d0ab7c9cdc42e2f07eb2d4ad3880 (patch) | |
tree | e8abae14847ba1d9291de11cdd68ac8d7fd4300c /Puzzle_Box/Puzzle_Box.pde | |
parent | aa5140ccb2ba0c7ced2f89ef002a96c924caf821 (diff) |
Diffstat (limited to 'Puzzle_Box/Puzzle_Box.pde')
-rw-r--r-- | Puzzle_Box/Puzzle_Box.pde | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Puzzle_Box/Puzzle_Box.pde b/Puzzle_Box/Puzzle_Box.pde index f3fa87d..21d9525 100644 --- a/Puzzle_Box/Puzzle_Box.pde +++ b/Puzzle_Box/Puzzle_Box.pde @@ -126,7 +126,7 @@ void loop() { PowerOff(); #endif - + // On the first loop, display the current message. if (firstRun && STATES[currentStage] == MESSAGE) { firstRun = false; displayMessage(currentMessageId++); @@ -136,7 +136,7 @@ void loop() { // Check for a stage transition int buttonState = digitalRead(BUTTON_PIN); - bool progressMade = false; + bool progressMade = false; // Set to true to move to the next state. if (buttonState == LOW) { // Find our stage switch (STATES[currentStage]) { @@ -159,6 +159,7 @@ void loop() { case OPEN: servo.write(OPEN_ANGLE); // open the box + // OPEN is the terminal state. Don't progress. break; default: @@ -173,15 +174,16 @@ void loop() { currentStage++; saveState(); - switch (STATES[currentStage]) { - case MESSAGE: - displayMessage(currentMessageId++); - currentStage++; - break; + if (MESSAGE == STATES[currentStage]) { + displayMessage(currentMessageId++); + currentStage++; + } - case OPEN: - servo.write(OPEN_ANGLE); // open the box - break; + // Note the fallthrough. If the next two stages are MESSAGE,OPEN, + // both will happen with the last successful button press. + if (OPEN == STATES[currentStage]) { + servo.write(OPEN_ANGLE); // open the box + // OPEN is the terminal state. Don't progress. } } |