summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Puzzle_Box/Puzzle_Box.pde24
1 files changed, 21 insertions, 3 deletions
diff --git a/Puzzle_Box/Puzzle_Box.pde b/Puzzle_Box/Puzzle_Box.pde
index 5da3dd8..088ef2f 100644
--- a/Puzzle_Box/Puzzle_Box.pde
+++ b/Puzzle_Box/Puzzle_Box.pde
@@ -49,6 +49,7 @@ int currentStage = MAIN_STAGE;
int attempt_counter;
int currentEyeAnimationStep = 0;
long lastLoopTime = 0;
+long lastAniTime = 0;
float currentDistance = -1;
@@ -92,6 +93,11 @@ void setup()
if (attempt_counter == 0xFF) // brand new EEPROM?
attempt_counter = 0;
+
+ lastLoopTime = millis();
+
+ pinMode(BUTTON_PIN, INPUT);
+ digitalWrite(BUTTON_PIN, HIGH);
}
/* The Arduino loop() function */
@@ -101,7 +107,7 @@ void loop()
// Check for a stage transition
int buttonState = digitalRead(BUTTON_PIN);
- if (buttonState = HIGH) {
+ if (buttonState == LOW ) {
currentStage = BUTTON_STAGE;
}
@@ -140,6 +146,7 @@ void doMainStage() {
* 1400 E on (1600 ms)
* 3000 Shift Anim. (200 ms/frame * 13 frames = 2600 ms)
* 5600 On (3000 ms)
+ * 8600 Back to the start
*/
int delta = millis() - lastLoopTime;
@@ -164,10 +171,13 @@ void doMainStage() {
// On
toggleEye(true);
- } else if (delta < 5600) {
+ } else if (delta <= 5600) {
// Shift Animation
stepEyeAnimation();
+ } else if (delta < 8600) {
+ // Do nothing for now
+
} else {
// On
toggleEye(true);
@@ -220,6 +230,7 @@ void doButtonStage() {
if (currentDistance == -1) {
Msg(lcd, "No :(", "Signal", 2000);
+ attempt_counter--;
return;
}
}
@@ -350,9 +361,14 @@ void drawEye(int location)
}
void stepEyeAnimation() {
+ long delta = millis() - lastAniTime;
+
+ if (delta >= 200) {
drawEye(eyeAnimationSteps[currentEyeAnimationStep]);
currentEyeAnimationStep++;
currentEyeAnimationStep = currentEyeAnimationStep % 12;
+ lastAniTime = millis();
+ }
}
void toggleEye(bool on) {
@@ -385,7 +401,7 @@ float toRandomUnit(int choice, float dist) {
// hands
case 3:
- return dist;
+ return dist;
}
}
@@ -410,6 +426,8 @@ char* getUnitLabel(int choice) {
case 3:
return " hn.";
+ default:
+ return " ?";
}
}