Skip to main content

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio()
 {
  Serial.println("INIZIO");

  currentMillis1_general = millis();
 
  total_1 = currentMillis1_general - currentMillis_general;
 
  Serial.println(total_1);

  buttonState = digitalRead(buttonPin);
 
  
  if(buttonState == HIGH){
 
    step_funzione = 1;
    delay(200);
  }
 
}

void countdown(){
 
  Serial.println("COUNTDOWN");

  display.setBrightness(7);

  currentMillis_general = millis();
 
  total_general = currentMillis_general - total_1;

  if(total_general - previousMillis_general >= interval_general){
 
    previousMillis_general += interval_general; 
 
    //previousMillis_general = currentMillis_general;
    m = new_tempo/60;
    s = new_tempo%60;
    
    new_tempo--;
    
  } 

  display.showNumberDec(m, true,2,0);
 
    display.showNumberDec(s, true,2,2);

  Serial.println(total_general);

  buttonState = digitalRead(buttonPin);
 
  if(buttonState == HIGH){
 
    step_funzione = 0;
    delay(200);
  }
 
}

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio()
 {
  Serial.println("INIZIO");

  currentMillis1_general = millis();
 
  total_1 = currentMillis1_general - currentMillis_general;
 
  Serial.println(total_1);

  buttonState = digitalRead(buttonPin);
 
  
  if(buttonState == HIGH){
 
    step_funzione = 1;
    delay(200);
  }
 
}

void countdown(){
 
  Serial.println("COUNTDOWN");

  display.setBrightness(7);

  currentMillis_general = millis();
 
  total_general = currentMillis_general - total_1;

  if(total_general - previousMillis_general >= interval_general){
 
    previousMillis_general += interval_general; 
 
    //previousMillis_general = currentMillis_general;
    m = new_tempo/60;
    s = new_tempo%60;
    
    new_tempo--;
    
  }
  display.showNumberDec(m, true,2,0);
 
    display.showNumberDec(s, true,2,2);

  Serial.println(total_general);

  buttonState = digitalRead(buttonPin);
 
  if(buttonState == HIGH){
 
    step_funzione = 0;
    delay(200);
  }
 
}

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio(){
  Serial.println("INIZIO");

  currentMillis1_general = millis();
  total_1 = currentMillis1_general - currentMillis_general;
  Serial.println(total_1);

  buttonState = digitalRead(buttonPin);
  if(buttonState == HIGH){
    step_funzione = 1;
    delay(200);
  }
}

void countdown(){
  Serial.println("COUNTDOWN");

  display.setBrightness(7);

  currentMillis_general = millis();
  total_general = currentMillis_general - total_1;

  if(total_general - previousMillis_general >= interval_general){
    previousMillis_general += interval_general; 
    //previousMillis_general = currentMillis_general;
    m = new_tempo/60;
    s = new_tempo%60;
    new_tempo--;
  } 

  display.showNumberDec(m, true,2,0);
  display.showNumberDec(s, true,2,2);

  Serial.println(total_general);

  buttonState = digitalRead(buttonPin);
  if(buttonState == HIGH){
    step_funzione = 0;
    delay(200);
  }
}
Formatted OP's code
Source Link
JRobert
  • 15.4k
  • 3
  • 25
  • 53

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio() { Serial.println("INIZIO");

currentMillis1_general = millis();

total_1 = currentMillis1_general - currentMillis_general;

Serial.println(total_1);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){

void inizio()
{
  Serial.println("INIZIO");

  currentMillis1_general = millis();

  total_1 = currentMillis1_general - currentMillis_general;

  Serial.println(total_1);

  buttonState = digitalRead(buttonPin);

  
  if(buttonState == HIGH){

    step_funzione = 1;
    delay(200);

}

}

void countdown(){

Serial.println("COUNTDOWN");

display.setBrightness(7);

currentMillis_general = millis();

total_general = currentMillis_general - total_1;

if(total_general - previousMillis_general >= interval_general){

  }

}

void countdown(){

  Serial.println("COUNTDOWN");

  display.setBrightness(7);

  currentMillis_general = millis();

  total_general = currentMillis_general - total_1;

  if(total_general - previousMillis_general >= interval_general){

    previousMillis_general += interval_general; 

    //previousMillis_general = currentMillis_general;
    m = new_tempo/60;
    s = new_tempo%60;
    
    new_tempo--;

} display.showNumberDec(m, true,2,0);

    
  }
  display.showNumberDec(m, true,2,0);

    display.showNumberDec(s, true,2,2);

Serial.println(total_general);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){


  Serial.println(total_general);

  buttonState = digitalRead(buttonPin);

  if(buttonState == HIGH){

    step_funzione = 0;
    delay(200);
  }

}

}

}

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio() { Serial.println("INIZIO");

currentMillis1_general = millis();

total_1 = currentMillis1_general - currentMillis_general;

Serial.println(total_1);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){

step_funzione = 1;
delay(200);

}

}

void countdown(){

Serial.println("COUNTDOWN");

display.setBrightness(7);

currentMillis_general = millis();

total_general = currentMillis_general - total_1;

if(total_general - previousMillis_general >= interval_general){

previousMillis_general += interval_general; 

//previousMillis_general = currentMillis_general;
m = new_tempo/60;
s = new_tempo%60;

new_tempo--;

} display.showNumberDec(m, true,2,0);

display.showNumberDec(s, true,2,2);

Serial.println(total_general);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){

step_funzione = 0;
delay(200);

}

}

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio()
{
  Serial.println("INIZIO");

  currentMillis1_general = millis();

  total_1 = currentMillis1_general - currentMillis_general;

  Serial.println(total_1);

  buttonState = digitalRead(buttonPin);

  
  if(buttonState == HIGH){

    step_funzione = 1;
    delay(200);
  }

}

void countdown(){

  Serial.println("COUNTDOWN");

  display.setBrightness(7);

  currentMillis_general = millis();

  total_general = currentMillis_general - total_1;

  if(total_general - previousMillis_general >= interval_general){

    previousMillis_general += interval_general; 

    //previousMillis_general = currentMillis_general;
    m = new_tempo/60;
    s = new_tempo%60;
    
    new_tempo--;
    
  }
  display.showNumberDec(m, true,2,0);

    display.showNumberDec(s, true,2,2);

  Serial.println(total_general);

  buttonState = digitalRead(buttonPin);

  if(buttonState == HIGH){

    step_funzione = 0;
    delay(200);
  }

}
Source Link

Function Millis() Arduino

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do this. So how can I find an alternative for this? In practice, when I pressed the button I started the countdown, while if I put it back, I went into the pause mode.


void inizio() { Serial.println("INIZIO");

currentMillis1_general = millis();

total_1 = currentMillis1_general - currentMillis_general;

Serial.println(total_1);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){

step_funzione = 1;
delay(200);

}

}

void countdown(){

Serial.println("COUNTDOWN");

display.setBrightness(7);

currentMillis_general = millis();

total_general = currentMillis_general - total_1;

if(total_general - previousMillis_general >= interval_general){

previousMillis_general += interval_general; 

//previousMillis_general = currentMillis_general;
m = new_tempo/60;
s = new_tempo%60;

new_tempo--;

} display.showNumberDec(m, true,2,0);

display.showNumberDec(s, true,2,2);

Serial.println(total_general);

buttonState = digitalRead(buttonPin);

if(buttonState == HIGH){

step_funzione = 0;
delay(200);

}

}