MIllis() time interval on countdown not working?

Hello,

I’m a airsoft player making a “bomb” (which does NOT explode).
My code is already working, but i need improve some “movie thing” in my bomb.

there is 3 wires, if the player CUT one those something happens:

wire A = bomb explode
wire B = bomb defuse
wire C = times goes faster (each X seconds reduces 60 seconds from the clock until the wire is connect again)

wire A is already working.
wire B working on it
wire C NEED HELP IN THIS ONE.

i’ve try millis(); delay(); delayMicroseconds();… the closes i can get is
start_num = start_num-0.001;

but its still too fast, and add more zeros to it dont work. (like 0.0001)
any ideas?

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

int config_tempo = 40; //pino de configuraçao do DIP switch
int config_tempo2 = 42; //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 = 30;
int explode = 0;
int fiorapido = 28;
int rapido = 0;
int fiodesarma = 26;
int desarma = 0;

long aux =0;

long start_num=1800;  // 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);
  
} 

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_radpio
  
  
    if((millis()/1000) < start_num){
    displayNumber(start_num -(millis()/1000));
     if (rapido == LOW){
      start_num = start_num-0.001;
      //I THINK IT MUST BE HERE "WIRE C"
      }
      
    }
    else {
    kabum();
    }

  
  if (explode == LOW){
    start_num=0;
    kabum();
  }
  
}

//Given a number, we display 10:22
//After running through the 4 numbers, the display is left turned off

//Display brightness
//Each digit is on for a certain amount of microseconds
//Then it is off until we have reached a total of 20ms for the function call
//Let's assume each digit is on for 1000us
//If each digit is on for 1ms, there are 4 digits, so the display
//is off for 16ms.
//That's a ratio of 1ms to 16ms or 6.25% on time (PWM).
//Let's define a variable called brightness that varies from:
//5000 blindingly bright (15.7mA current draw per digit)
//2000 shockingly bright (11.4mA current draw per digit)
//1000 pretty bright (5.9mA)
//500 normal (3mA)
//200 dim but readable (1.4mA)
//50 dim but readable (0.56mA)
//5 dim but readable (0.31mA)
//1 dim but readable in dark (0.28mA)

void displayNumber(int toDisplay) {
#define DISPLAY_BRIGHTNESS  800

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  long beginTime = millis();

  for(int digit = 4 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_ON);
      break;
    case 2:
      digitalWrite(digit2, DIGIT_ON);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      break;
    }

    //Turn on the right segments for this digit
    if (digit == 3) {
      lightNumber(toDisplay % 6);
      toDisplay /= 6;
    }
    else {
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
    }

    delayMicroseconds(DISPLAY_BRIGHTNESS); 
    //Display digit for fraction of a second (1us to 5000us, 500 is pretty good)

    //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
  }

  while( (millis() - beginTime) < 10) ; 
  //Wait for 20ms to pass before we paint the display again
}

void kabum(){
  // reached zero, flash the display
    time=millis();
    while(millis() < time+200) {
      displayNumber(0);  // display 0 for 0.2 second
    }
    time=millis();    
    while(millis() < time+200) {
      lightNumber(10);  // Turn display off for 0.2 second
    }
}
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  LOW
#define SEGMENT_OFF HIGH

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  }
}

I dont know what its going on anymore…

this is my loop:

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_radpio
  
  
    if((millis()/1000) < start_num){
      displayNumber(start_num -(millis()/1000));
      if (rapido == LOW){
        delayMicroseconds(4000);
        delayMicroseconds(4000);
        delayMicroseconds(4000);
        delayMicroseconds(4000);
        delayMicroseconds(4000);
        delayMicroseconds(4000);
        start_num -= 1;
      }
    }

why delayMicroseconds(4000); in 5 rolls works and delayMicroseconds(20000); in a single line dont?
im totally lost here.

why delayMicroseconds(4000); in 5 rolls works and delayMicroseconds(20000); in a single line dont?
im totally lost here.

The reference on delayMiroseconds() states that " the largest value that will produce an accurate delay is 16383" delayMicroseconds() - Arduino Reference

The internal workings of delayMicroseconds() uses dummy cycles, and there is a multiplication of the entered microseconds value by 4 with a 16MHz Arduino. Values larger than 16383 overflow with this multiplication and can become much shorter values.

In your case, a desired delay of 20 milliseconds will become approximately 3.6 ms.

thanks

IHMO this whole discussion is inappropriate in an open site.

Helping in a project like this possibly gives instructions that should not be shared.

.

"I'm a airsoft player "
says it all right there.

Description could have easily been

wire A = bomb explodeLED that was on steady now flashes
wire B = bomb defuseLED turns off

and there would have been no question re: offering help.

I don't see the love affair with promoting killing of any kind in play or otherwise or making this commonplace and socially acceptable.

Don't consider this fun or entertaining.

Seems like anything goes if a dollar can be exchanged, oh, I guess it's always been that way.

edit
It just takes one person to make this 'toy' into horrible life changes for innocent bystanders.
.

None-the-less, there are plenty of places to have paint-ball battles and such with your friends and co-workers, and airsoft is just part of that. No one's getting hurt.

I see fa more people getting hurt from poor drivers. There were 2 big accidents this weekend, one a cab driver drive into a stand of fellow cabbies, the other an old woman who mistook her gas for brake, drove thru a fence and into a pool. I don't like being around crowds anymore with that kind of stuff occurring. Not likely to get run over being out on the golf course.