Blink with out delay

Were you you told to look at the blink with out delay tutorial? did you understand what was going on with it? Well I sure don't and I'm not sure how helpful it would be to my projects. So I'm going to post the code line by line, and I want comments on all the things I explain wrong. your help is greatly appreciated

const int ledPin =  13;

const = constant : cannot be changed int = integer : a number up to 255? (medium sized)

int ledState = LOW;
long previousMillis = 0;

long= longer number; a number up to XXXXXX (large sized) a "long" variable called "previousMillis" set to "0"

long interval = 1000

A "Long" variable called "interval" set to "1000"

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{

ok

if (millis() - previousMillis > interval) {

if the differance between the variables "millis" (number of milliseconds the arduino has been running) and previousMillis (initally set to 0) is greater than "interval" (1000) DO:

previousMillis = millis();

set the number of seconds the arduino has been running to the variable "Previousmilis" and:

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

if the led is off, turn it on, otherwise turn it off.

    digitalWrite(ledPin, ledState);
  }
}

Write the state to the pin

so this is the part I don't understand. the "clock" counts to 1001mS, since the initial value of previousmilis is 0, 1001-0=1001 1001>1000

if (millis() - previousMillis > interval) {
 previousMillis = millis();

so the clock is reset to 0 ? because previousmilis = 0, so why doesn't it just say millis = 0 ?

is this explanation correct?

See my reply to your previous post.

"int" a number -32768..+32767 "long" a number -2147483648..+2147483647

"millis" isn't a variable, it's a function. You can't set a function to zero.

so this is the part I don’t understand.
the “clock” counts to 1001mS, since the initial value of previousmilis is 0, 1001-0=1001
1001>1000

When the Arduino is reset, the first call to millis() will return a small number, typically less than 200. It takes some time to establish serial communications (if required), etc. in setup(), and there is some stuff that happens before setup() is called.

So, the first time in loop, millis() might return 200. With previousMillis being 0, 200 - 0 < 1000, so the if test is false. So, nothing happens. Loop gets called again.

A few milliseconds have elapsed, so maybe millis() returns 210. Still less than 1000, so nothing happens, and loop is called again.

After a number of passes through loop, millis() finally returns 1003. 1003 - 0 > 1000, so the if test is now true. previousMillis is set to the value returned by another call to millis(), which might return 1004 this time. The LED is toggled, and the if test ends, and loop is called again.

This time, millis() might return 1008. 1008 - 1004 < 1000, so the if test is false, so nothing happens. Loop is called again.

This continues to happen until millis() returns a value greater then 2004, when the cycle starts over again.

O, ok. so previousmilis=the value of the clock the last time the statement was true! I get it. thanks Paul S. so my new question is can you ?

millis()=0

Reply #1:

"millis" isn't a variable, it's a function. You can't set a function to zero.