diff --git a/Combined/arm_warmer_v6.6/arm_warmer_v6.6.ino b/Combined/arm_warmer_v6.6/arm_warmer_v6.6.ino index 0f780bc7235d40cfb34eddb6b18ba02becfbf973..de6e5825a2d9e2b0946fbe06ced22f8a63aebbed 100644 --- a/Combined/arm_warmer_v6.6/arm_warmer_v6.6.ino +++ b/Combined/arm_warmer_v6.6/arm_warmer_v6.6.ino @@ -64,22 +64,24 @@ #define DEBUG 1 -#define HOLD_DELAY_S 5 +#define HOLD_DELAY_S 3 -#define TAP_DELAY 20 -uint32_t hold_counter = millis(); -uint32_t tap_counter = millis(); -uint32_t button_timer = millis(); -uint32_t tap_cooldown = millis(); +#define TAP_DELAY 100 +uint64_t hold_counter = millis(); +uint64_t tap_counter = millis(); +uint64_t button_timer = millis(); +uint64_t tap_cooldown = millis(); bool press = false; bool holding = false; bool tapping = false; -bool LED_on = false; +bool LED_on = true; + +bool no_fix_flipflop = false; //New timer in v6.2 for LED flickering issue #define LED_REFRESH_DELAY 300 //LEDs refresh every 500 milliseconds -long LED_REFRESH_TIMER = millis(); //timer variables for LED refresh +uint64_t LED_REFRESH_TIMER = millis(); //timer variables for LED refresh //Bluetooth route uploading variables and constants float b = 0.0; //floating point value coming in through Bluetooth serial @@ -102,7 +104,7 @@ void update_route_vars();//update waypoint num, distance and radius from eeprom //LED Timer Variable - Timeout before showing progress bar #define LED_TIMEOUT 10000 //set to 10 seconds -#define LED_FIX_TIMEOUT 50000//shows NO FIX on LEDs every 3 seconds +#define LED_FIX_TIMEOUT 60000//shows NO FIX on LEDs every 3 seconds #define STARTUP_BATTERY_TIME 3000//shows battery level for 3 seconds on startup //BATTERY VOLTAGE READING PIN, VARIABLE AND FUNCTION PROTOTYPE @@ -159,9 +161,9 @@ BluetoothSerial s;//normal bluetooth serial int heading_offset;//constant offset for tilt-compass heading - defined in setup() //timer variables for two different approx. frequencies in loop -long timer = millis(); -long LED_timer = millis();//brings LED mode back to progress bar after fixed interval -long LED_FIX_timer = millis(); //timer to keep track of showing NO FIX on LEDs at intervals +uint64_t timer = millis(); +uint64_t LED_timer = millis();//brings LED mode back to progress bar after fixed interval +uint64_t LED_FIX_timer = millis(); //timer to keep track of showing NO FIX on LEDs at intervals //Touch sensor value variable uint8_t touchSensorState = 0; @@ -294,7 +296,6 @@ void setup() { LED.led_function(); LED.setPixels(); delay(STARTUP_BATTERY_TIME);//display for x seconds - hold_counter = millis(); Serial.println("Done"); } @@ -409,37 +410,39 @@ void loop() { // Read the state of the capacitive touch board //touch sensor detection runs faster than the rest of the code - if(millis()-button_timer > 10){ + if(millis()-button_timer >= 10){ button_timer = millis(); - - touchSensorState = digitalRead(TOUCH_SENSOR); + } - - if(touchSensorState){ + if (touchSensorState){ press = true; - Serial.println("----------------press true"); + //Serial.println("----------------press true"); } else{ - if (millis() - hold_counter > HOLD_DELAY_S*1000){ - LED_on = !LED_on; - Serial.println("----------------holding else"); + if ((millis() - hold_counter) >= (HOLD_DELAY_S*1000)){ + if(LED_on == 1) + LED_on = 0; + else + LED_on = 1; + //Serial.println("----------------holding else"); } - else if (!tapping && millis() - hold_counter > 20){ + else if (!tapping && ((millis() - hold_counter) >= TAP_DELAY)){ tapping = true; tap_cooldown = millis(); modes += 1; - if (modes > 4) modes = 0; + if (modes > 4) + modes = 0; LED_timer = millis(); - Serial.println("----------------tapping else"); + //Serial.println("----------------tapping else"); } hold_counter = millis(); - Serial.println("----------------reset hold counter"); + //Serial.println("----------------reset hold counter-------------------------"); } - if(!LED_on) + if(LED_on) LED.brightness = 0; else LED.brightness = BRIGHTNESS; @@ -448,7 +451,6 @@ void loop() { if(millis() - tap_cooldown > 500){ tapping = false; } - } /* if (touchSensorState) @@ -464,6 +466,10 @@ void loop() { if (millis() - timer > 1000) { timer = millis(); // reset the timer + if(no_fix_flipflop) + no_fix_flipflop = 0; + else + no_fix_flipflop = 1; northHeading = getHeading();//store north in global variable //NO FIX? -- only prints out compass heading @@ -525,9 +531,27 @@ void loop() { s.println(offTrackWaypointDirection(), 10); } - } - + //Revert back to progress bar when LED Timer expires + if (millis() - LED_timer > LED_TIMEOUT) + { + LED_timer = millis(); //Reset LED timer + + //default to off-track when off-route + //COMMENT OUT THIS SECTION FOR TESTING PURPOSES WITH INVALID ROUTE + if (isOffRoute == true) + { + modes = 6; + input = offTrackHeading; + } + //default to progress bar if on route + else + { + modes = 0; + input = progress; + } + } + } //RUN WHEN NO GPS FIX - MAINLY FOR LED NO FIX INDICATOR WITH DELAYS else { @@ -535,23 +559,14 @@ void loop() { //Increased delays in this if statement should be fine - Arm Warmer is not operational with no fix if ((millis() - LED_FIX_timer > LED_FIX_TIMEOUT)) { - LED.modes = 5; //change mode to NO FIX indicator - - LED.input = 0; //Displays "NO" - LED.led_function(); - LED.setPixels(); - delay(750); //Display for 1 second - - LED.input = 1; //Displays "FIX" - LED.led_function(); - LED.setPixels(); - delay(750); //Display for 1 second - + modes = 5; //change mode to NO FIX indicator + LED_FIX_timer = millis(); //Reset LED_FIX timer } //LED mode selection below will find the correct desired mode afterwards + } - + } //--> MAIN LED MODES @@ -578,26 +593,6 @@ void loop() { - //Revert back to progress bar when LED Timer expires - if (millis() - LED_timer > LED_TIMEOUT) - { - LED_timer = millis(); //Reset LED timer - - //default to off-track when off-route - //COMMENT OUT THIS SECTION FOR TESTING PURPOSES WITH INVALID ROUTE - if (isOffRoute == true) - { - modes = 6; - input = offTrackHeading; - } - //default to progress bar if on route - else - { - modes = 0; - input = progress; - } - } - //only update LEDs every LED_REFRESH_DELAY (500ms) defined above if (millis() - LED_REFRESH_TIMER > LED_REFRESH_DELAY) { @@ -607,8 +602,15 @@ void loop() { LED.input = input; //Serial.println("Displaying on LEDs."); + if(modes == 5) + input = no_fix_flipflop; //Displays "NO" + + + //display on LEDs -- I put it here for now because I'm not sure if LEDs should refresh only after the 1Hz loop + LED.modes = modes; + LED.input = input; LED.led_function(); LED.setPixels(); } @@ -982,4 +984,4 @@ void serialDataBL() s.println(northHeading); s.println("--------------------------------------------------------------------"); -} \ No newline at end of file +}