Airsoft Prop bomb 3 wires

Hello guys.

I'm having terrible problems with my custom bomb
(calm down bro, its fake and DO NOT explode anything)

It has 3 wires:
WIRE A = "explode" = if cut, time goes to zero and game over.
WIRE B = "rapido" = if cut, times goes faster (removes 1 minute bomb time for every 4 seconds real life time).
WIRE C = "desarma" = if cut, bomb stops the timer.

the connection on my board is like this:

3.3v |---------WIRE A ---------- A2
arduino ------|--------WIRE B----------- A3
|--------WIRE C------------ A4

the initial value to set the amount of time, in seconds is start_num (wich is 20 to test)
This is my code so far:

int segA = 6;
int segB = 2;
int segC = 10;
int segD = 12;
int segE = 13;
int segF = 5;
int segG = 9;
int digit1 = 7;
int digit2 = 4;
int digit3 = 3;
int digit4 = 8;
int dot = 11;

int config_tempo = A0; //pino de configuraçao do DIP switch
int config_tempo2 = A1; //pino de configuraçao do DIP switch
int config1 = 0; //auxiliar do DIP switch para o incremento do tempo da bomba
int config2 = 0; //auxiliar do DIP switch para o incremento do tempo da bomba

int fioexplode = A2;
int fiorapido = A3;
int fiodesarma = A4;

int tempolido = 0;
boolean explode = false;
boolean rapido  = false;
boolean desarma = false;

boolean permite_desarmar = true;
boolean lido = false;
boolean encerra_bomba = false;
boolean bombaexplodiu = false;
boolean bombadesarmou = false;

unsigned long aux=0;
unsigned long intervalo = 1;
unsigned long tempo_final;

int som = A6; //o correto eh A5
 
long start_num=20;  // tempo inicial da bomba EM SEGUNDOS (1800 segundos= 30 MINUTOS)
unsigned long time;

void setup() {   
  delay (100); //delay colocado pq tava rolando uma interferencia na leitura dos DIP switch;
  

  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(dot, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  
  pinMode(13, OUTPUT);
  
  pinMode(config_tempo, INPUT);
  pinMode(config_tempo2, INPUT);
  config1 = digitalRead(config_tempo);
  config2 = digitalRead(config_tempo2);
  
  if (config1 == HIGH){
    start_num=start_num+900;
  }
  
  if (config2 == HIGH){
    start_num=start_num+900;
  }
  
  pinMode(fioexplode, INPUT);
  pinMode(fiorapido, INPUT);
  pinMode(fiodesarma, INPUT);
  
  pinMode(som, OUTPUT);
} 
  
 

void loop() {
  digitalWrite(dot, LOW); //separador no display dos min e segu "mm:ss" 
  explode = digitalRead(fioexplode); //check fio_explode
  desarma = digitalRead(fiodesarma); //check fio_desarma
  rapido  = digitalRead(fiorapido);   //check fio_rapido
 
  if (rapido == LOW) {
    for (int i=0; i <= 1000; i++){
      start_num = start_num - 0.001;
   } 
  }

  if (desarma == LOW){
    defused();
  }
  
  else if (((millis()/1000) < start_num) && (bombaexplodiu == false) && (bombadesarmou == false)){
    displayNumber(start_num -(millis()/1000));
  }

  else {
    kabum();
  }  
 
} //FIM LOOP

I'm facing two problems:

  1. WIRE B , how to control the speed?
    i've try things like start_num = start_num - 0.001; (or even more zeros)

  2. WIRE C, how stop the timmer?
    so far, if the hire is cut, all segments is OFF

LONTRAGORDA:

  1. WIRE B , how to control the speed?
    i've try things like start_num = start_num - 0.001; (or even more zeros)

'start_num' is a long integer. Adding or subtracting any value less than 1 will do nothing because integers count by 1's.

LONTRAGORDA:
2. WIRE C, how stop the timmer?
so far, if the hire is cut, all segments is OFF

You can't "stop the timer" because you are displaying "(start_num - (millis()/1000))". You should use the BlinkWithoutDelay example to subtract 1 from 'start_num' each time 1000 milliseconds have passed. Use a shorter interval to run the clock faster (500 milliseconds would run the clock twice as fast). Stop subtracting 1's when you want to "stop the clock".

wow, nice explanations!
i will try here, thanks =D

(removes 1 minute bomb time for every 4 seconds real life time)

So that would be 15 times as fast. 1000/15 is 66.666... milliseconds. It has to be an integer so call it 67.

const byte TriggerPin = 2;   // Cut this to detonate
const byte SpeedUpPin = 3;  // Cut this to speed up the clock
const byte DisarmPin = 4;  // Cut this to disarm the bomb

const unsigned long REGULAR_SPEED = 1000;
const unsigned long FAST_SPEED = 67;

unsigned long ClockInterval = REGULAR_SPEED;
unsigned long IntervalStartTime;

int SecondsToBoom = 180;  //  Three minutes
bool TimerRunning = true;

void setup() {
  /// Put all the pin setup here
  IntervalStartTime = millis();
}

void loop() {
  // Check inputs to see if the bomb should detonate
  if (TimerRunning  && digitalRead(TriggerPin)) {
    TimerRunning = false;  // Stop the clock to show how much time was left
    /////  EXPLODE  //////
  }

  // Check the Speed Up input to see if the timer should speed up
  if (digitalRead(SpeedUpPin))
    ClockInterval = FAST_SPEED;  // Speed up the clock

  // Check the Disarm input to see if the bomb should disarm
  if (TimerRunning && digitalRead(DisarmPin)) {
    TimerRunning = false;  // Just stop the clock
  }


  if (TimerRunning && millis() - IntervalStartTime >= ClockInterval) {  // Time to tick
    IntervalStartTime += ClockInterval;  // Start a new interval
    SecondsToBoom--;
    if (SecondsToBoom == 0) {
      TimerRunning = false;  // Stop the clock
      /////////// EXPLODE  ///////////////
    }
  }

  // display(SecondsToBoom);
}

I've made some changes in the loop cicle:

void loop() {
  digitalWrite(dot, LOW); //separador no display dos min e segu "mm:ss" 
  explode = digitalRead(fioexplode); //check fio_explode
  desarma = digitalRead(fiodesarma); //check fio_desarma
  rapido  = digitalRead(fiorapido);   //check fio_rapido
  
  aux2 = (start_num -(millis()/500));
  
  if (rapido == LOW){
    if (millis() >= (aux + 100)){
      tempofinal = (tempofinal-1);
      aux = millis();
      start_num = start_num-1;
    }
    tone(som, 5500, 50);
    tone(som, 500, 30);
  } 
  
  if (millis() >= (aux + 1000)){
    tempofinal = (start_num -(millis()/1000));
    aux = millis() ;
    //tone(som, 5500, 100);
  }
  
  
  
  if ((millis()/1000) < start_num){
    displayNumber(tempofinal);  
  }

 
} //FIM LOOP -- END LOOP

now its easier to ajust time control...
BUT..... the idea of WIRE B (faster wire) is:
if someone cut, you have to put it back again before cut another wire,
in my code, if you put the wire back again, the time isn`t stable and you lose some seconds (or in another code i've set, time goes back(?) again).

@.@ thanks again for explain things =D

I`m not familiar with arduino, but... programming are almost same...

If you use "case"? :smiley: I remember one program constructed with "if" and "case".

switch (var) {
    case 1:
      //do something when var equals 1
      break;
    case 2:
      //do something when var equals 2
      break;
    default: 
      // if nothing else matches, do the default
      // default is optional
    break;
  }

When you loop this code - it will always checks cases. If we imagina that case 2 is cutted wire and default - standart, when you repair your wire - it will switch in default.

If i correctly understood your idea.