Hey everyone, im working on a launch system for a model rocket. Im running into an issue where my countdown starts whether i have flipped the "Go No Go switch". If i leave the switch in "Standby (sb)" the program displays "sb" as it should. but once its flipped it appears the timer started when the arduino mega started. im not sure how to prevent this. I will include my code below.
#include "SevSeg.h"
SevSeg sevseg;
volatile static int deciSeconds;
volatile bool GNG = false;
void setup() {
//setting up launch leds
int red = 53;
int yellow = 51;
int blue = 49;
pinMode(blue, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
//setting up the display
byte numDigits = 2;
byte digitPins[] = {4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE;
bool updateWithDelays = false; // Default. Recommended
bool leadingZeros = true;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
sevseg.setBrightness(90);
//setting up the button interrupts
attachInterrupt(digitalPinToInterrupt(18), GNGswitch, RISING); // if timer is not counting down flip reset switch
}
void loop() {
if (GNG) {
int red = 53;
int yellow = 51;
int blue = 49;
static unsigned long timestamp = millis();
// deciSeconds = 100; //10 deciSeconds = 1 sec
if (millis() - timestamp >= 1000 && deciSeconds > 0 ) {
timestamp += 100;
deciSeconds--; // 100 milliSeconds is equal to 1 deciSecond
sevseg.setNumber(deciSeconds, 1);
digitalWrite(49, LOW);
digitalWrite(51, HIGH);
}
if (deciSeconds == 0) {
sevseg.setChars("ig");
digitalWrite(51, LOW);
digitalWrite(53, HIGH);;
}
}
else {
sevseg.setChars("sb");
digitalWrite(49, HIGH);
deciSeconds = 100;
}
sevseg.refreshDisplay(); // Must run repeatedly
}
void GNGswitch() {
if (!GNG) {
deciSeconds = 100;
GNG = true;
}
}