summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-08-14 08:31:17 -0700
committerJesse Morgan <jesse@jesterpm.net>2014-08-14 08:44:54 -0700
commit664a207a42d0d0ab7c9cdc42e2f07eb2d4ad3880 (patch)
treee8abae14847ba1d9291de11cdd68ac8d7fd4300c
parentaa5140ccb2ba0c7ced2f89ef002a96c924caf821 (diff)
Open the box immediately after displaying the last message.HEADmaster
-rw-r--r--Makefile2
-rw-r--r--Puzzle_Box/Puzzle_Box.pde22
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.
}
}