From 3439e192069f315e986f7b51b6e68c41983138bc Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 28 Apr 2012 23:13:51 -0700 Subject: Box done! --- Puzzle_Box/Puzzle_Box.h | 13 +++++++---- Puzzle_Box/Puzzle_Box.pde | 55 +++++++++++++++++++++++++++++++---------------- Puzzle_Box/quotes.h | 4 ++-- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Puzzle_Box/Puzzle_Box.h b/Puzzle_Box/Puzzle_Box.h index 46a0bdb..bd5b2fb 100644 --- a/Puzzle_Box/Puzzle_Box.h +++ b/Puzzle_Box/Puzzle_Box.h @@ -22,6 +22,7 @@ void doCheckOverrideSerial(); void doCheckAccess(); void PowerOff(); float toRandomUnit(int choice, float dist); +void showQuote(int quote); /* Fixed values should not need changing */ static const int DEF_ATTEMPT_MAX = 50; @@ -31,6 +32,9 @@ static const int EEPROM_OFFSET = 100; static const int MAIN_STAGE = 1; static const int BUTTON_STAGE = 2; +/* Random Units */ +static const int NUMBER_OF_UNITS = 4; + /* Eye Animation Steps (12 step program) */ static const int eyeAnimationSteps[] = { 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 1, 0 }; static const int MAX_EYE_STEPS = 13; @@ -40,9 +44,10 @@ static const int MAX_EYE_STEPS = 13; /* These values should be adjusted according to your needs */ static const int CLOSED_ANGLE = 80; // degrees -static const int OPEN_ANGLE = 180; // degrees -static const float DEST_LATITUDE = 47.512157; -static const float DEST_LONGITUDE = -119.498119; -static const int RADIUS = 5; // meters +static const int OPEN_ANGLE = 200; // degrees + +static const float DEST_LATITUDE = 47.272697; +static const float DEST_LONGITUDE = -122.021201; +static const int RADIUS = 100; // meters diff --git a/Puzzle_Box/Puzzle_Box.pde b/Puzzle_Box/Puzzle_Box.pde index 53ff040..61c8589 100644 --- a/Puzzle_Box/Puzzle_Box.pde +++ b/Puzzle_Box/Puzzle_Box.pde @@ -37,6 +37,7 @@ For supporting libraries and more information see #include "Puzzle_Box.h" #include "the_eye.h" +#include "quotes.h" /* Hardware Objects */ NewSoftSerial nss(GPSrx, GPStx); @@ -53,6 +54,7 @@ long lastAniTime = 0; float currentDistance = -1; bool im_ready = false; +int currentUnit = 0; /* The Arduino setup() function */ @@ -99,12 +101,13 @@ void setup() pinMode(BUTTON_PIN, INPUT); digitalWrite(BUTTON_PIN, HIGH); + + randomSeed(analogRead(2)); } /* The Arduino loop() function */ void loop() { - // Check for a stage transition int buttonState = digitalRead(BUTTON_PIN); @@ -125,11 +128,9 @@ void loop() } // Find the current distance just to be ready - /*if (doUpdateDistance() && im_ready == false) { - Msg(lcd, "GPS", "Rowered!", 2000); + if (doUpdateDistance() && im_ready == false) { im_ready = true; - }*/ - + } // Check for override login attempts @@ -200,12 +201,17 @@ void doButtonStage() { // Plan to go back to the main stage currentStage = MAIN_STAGE; + // Screen on please. + toggleEye(true); + /* increment it with each run */ ++attempt_counter; // TODO: Witty Saying + //showQuote(4); + /* Greeting */ - Msg(lcd, "Hello", "Jesse!", 1500); + Msg(lcd, "Hello", "Craig!", 1500); Msg(lcd, "Welcome", "to your", 1500); Msg(lcd, "puzzle", "box!", 1500); @@ -230,7 +236,7 @@ void doButtonStage() { if (currentDistance == -1) { Msg(lcd, "Seeking", "Signal..", 0); long start = millis(); - while (!doUpdateDistance() && millis() - start < 5000); + while (!doUpdateDistance() && millis() - start < 10000); if (currentDistance == -1) { Msg(lcd, "No :(", "Signal", 2000); @@ -290,15 +296,13 @@ void doCheckAccess() { else { // Get a random unit - int unit = 0; - - lcd.clear(); lcd.setCursor(0, 0); - lcd.print("Distance"); - lcd.setCursor(0, 1); - lcd.print((int)toRandomUnit(unit, currentDistance)); - lcd.print(getUnitLabel(unit)); + lcd.print((long)toRandomUnit(currentUnit, currentDistance)); + lcd.setCursor(0, 1); + lcd.print(getUnitLabel(currentUnit)); + + currentUnit = (currentUnit + 1) % NUMBER_OF_UNITS; delay(4000); Msg(lcd, "Access", "Denied!", 2000); @@ -400,19 +404,24 @@ void toggleEye(bool on) { */ float toRandomUnit(int choice, float dist) { switch (choice) { - // feet + // meters case 0: + return dist; - // meters + // feet case 1: + return dist * 3.2808; // cubits case 2: + return dist * 2.18; // hands case 3: + return dist * 9.84252; - return dist; + default: + return -1; } } @@ -435,10 +444,20 @@ char* getUnitLabel(int choice) { // hands case 3: - return " hn."; + return " hh."; default: return " ?"; } } +void showQuote(int id) { + int pairs = messages[id].pairs; + + for (int i = 0; i < pairs; i++) { + Msg(lcd, + messages[id].lines[i].line1, + messages[id].lines[i].line2, + 1000); + } +} diff --git a/Puzzle_Box/quotes.h b/Puzzle_Box/quotes.h index 02c3169..ea29cd2 100644 --- a/Puzzle_Box/quotes.h +++ b/Puzzle_Box/quotes.h @@ -8,8 +8,8 @@ typedef struct { line_pair_t * lines; } message_t; -const int msgcount = 12; -const message_t messages[] = { +static const int msgcount = 12; +static const message_t messages[] = { { 1, (line_pair_t []){ {"That is" , "my eye!" } } }, { 1, (line_pair_t []){ {"Ouch!" , "" } } }, { 1, (line_pair_t []){ {"Hey!" , "" } } }, -- cgit v1.2.3