Countdown timer (millis) on serial monitor

I am sorry, I think my question is not quite clear. This is my assignemnt: Use the code below, but modify it so it will be a countdown timer from 10 to 0. Tips I have been given:
Change the printing to countdown
Change the time from stopwatch up tp countdown
Very important: Use an if function to check if 0 has been reached.
The source code I have to modify is:

void setup () {
Serial.begin (9600);
}
void loop () {
Serial.print ("Seconds passed after start: ");
Serial.println (millis() / 1000);
delay (1000):

}

Maybe I should have started my post with this....keep it mind for next time.

joery81:
I am sorry, I think my question is not quite clear. This is my assignemnt: Use the code below, but modify it so it will be a countdown timer from 10 to 0. Tips I have been given:
Change the printing to countdown
Change the time from stopwatch up tp countdown
Very important: Use an if function to check if 0 has been reached.
The source code I have to modify is:

void setup () {

Serial.begin (9600);
}
void loop () {
Serial.print ("Seconds passed after start: ");
Serial.println (millis() / 1000);
delay (1000):

}




Maybe I should have started my post with this....keep it mind for next time.

I assume you mean if statement not if function.

Serial.println (millis() / 1000);

Always prints the time since the Arduino reset. I don't see any indication in the assignment you have to keep the millis() call.

void setup () {
Serial.begin (9600);
}
void loop () {
static int counter = 10;
Serial.println (counter);
if (counter-- == 0) counter = 10;
delay (1000);

}

The simplest way using an if statement.

ToddL1962:
I assume you mean if statement not if function.

Serial.println (millis() / 1000);

Always prints the time since the Arduino reset. I don't see any indication in the assignment you have to keep the millis() call.

We have to use this code and minimiza the changes. So what I know I can't use an int, can only use the statements I mentioned. I think there is something wrong with the description after if, but I don't know what. The counter has to countdown from 10 to 0, but in steps of one second (we have to use the delay (1000)). Then when hitting 0 the countdown must stup or write 0 but not go to the highest number it knows.

One of the silliest programs I have ever written but it works and meets your requirements:

void setup () {
Serial.begin (9600);
}
void loop () {
Serial.println (10 - (millis()/1000)%11);
if ((millis()/1000)%11 == 10) Serial.println("0 reached");
delay (1000);
}

ToddL1962:
One of the silliest programs I have ever written but it works and meets your requirements:

void setup () {

Serial.begin (9600);
}
void loop () {
Serial.println (10 - (millis()/1000)%11);
if ((millis()/1000)%11 == 10) Serial.println("0 reached");
delay (1000);
}

Thanks for helping me with the program, even if it is a waste of your time ;). Can you tell me what %11 does, it is something the course did not mention yet.

Read the documentation early, read the documentation often

% is the modulo operator.

I was thinking the wrong way. Last weekend I realised (in the middle of the night when I woke up in my sleep) that I could do it really easy. In the IF statment I said: if millis =< 10000 do the countdown and, else do the zero thing. So I was thinking the wrong way and asking the wrong questions. I am sorry for wasting your time but also want to thank you for the help and quick response.

joery81:
I was thinking the wrong way. Last weekend I realised (in the middle of the night when I woke up in my sleep) that I could do it really easy. In the IF statment I said: if millis =< 10000 do the countdown and, else do the zero thing. So I was thinking the wrong way and asking the wrong questions. I am sorry for wasting your time but also want to thank you for the help and quick response.

Make sure you understand that the statement if (millis() =< 10000) will only work for the first 10 seconds. After that you will always execute the else. millis() does not go back to 0 until you reset the Arduino.

Well if you ever wanted to deliberately wanted to reset your millis() which I don't think will be of any use anytime soon...:

unsigned long new_value = 0;
extern volatile unsigned long timer0_millis;

void setup()
{
  Serial.begin ( 9600 );
}

void loop()
{
  Serial.println ( millis() );

  setMillis( new_value );
}

void setMillis(unsigned long new_millis)
{
  uint8_t oldSREG = SREG;
  cli();
  timer0_millis = new_millis;
  SREG = oldSREG;
}