From 664a207a42d0d0ab7c9cdc42e2f07eb2d4ad3880 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 14 Aug 2014 08:31:17 -0700 Subject: Open the box immediately after displaying the last message. --- Makefile | 2 ++ Puzzle_Box/Puzzle_Box.pde | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index e1e15ef..9d049b9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ #LIBRARIES := EEPROM BOARD := uno +CPPFLAGS += -Wno-write-strings + include arduino.mk 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. } } -- cgit v1.2.3