recording "on time" with millis

im thinking more along the lines of, while relay low relaycurrent = millis, when relay high relayprev = millis; then
relayprev minus relaycurrent = elapsed time of 10 seconds. relayelapsed = replayrev - relaycurrent.

then the next time it comes around same thing except this time it just adds the difference to relayelapsed so now relayelapsed = 20; when its comes around soo many more times that relayelapsed = 100; then it will trigger relay2 for the interval. i cannot figure out what to do with millis,then relayelapsed can be reset back to 0 after every relay 2 off event??

Small wonder it won't compile...

unsigned long relay2offinterval = "untill relay has been on a total of 30 throughout its on off times";

this is a joke do i have to donate or something to get help around here i don't get it whats the problem

notsolowki:
this is a joke do i have to donate or something to get help around here i don't get it whats the problem

As a matter of fact, with that kind of attitude, you do.

You are rapidly putting me off helping you because you are not listening to the ideas given to you.

You said :

i DO NOT want it to count the amount of time between ON and OFF because it will not always be the same. i need it to count the time relay is LOW and pause the timer when its high, then when it goes LOW again add the elapsed time to the previous elapsed time

So, as previously suggested, when the relay becomes LOW (not is LOW) save the time from millis(). When the relay becomes HIGH (not is HIGH save the time from millis(). Subtract the LOW start time from the HIGH start time and add it to a variable holding the total. Compare the total with the target elapsed time and act accordingly.

If you want/need to act when the elapsed time exceeds the target whilst the relay is still LOW, then each time through loop() whilst the relay is LOW, you need to compare the target with the difference between the current time minus the time the relay went LOW plus the previously recorded total elapsed time.

UKHeliBob:
You are rapidly putting me off helping you because you are not listening to the ideas given to you.

You said :
So, as previously suggested, when the relay becomes LOW (not is LOW) save the time from millis(). When the relay becomes HIGH (not is HIGH save the time from millis(). Subtract the LOW start time from the HIGH start time and add it to a variable holding the total. Compare the total with the target elapsed time and act accordingly.

If you want/need to act when the elapsed time exceeds the target whilst the relay is still LOW, then each time through loop() whilst the relay is LOW, you need to compare the target with the difference between the current time minus the time the relay went LOW plus the previously recorded total elapsed time.

Yes this is exactly what i need. im having a hell of a time figuring out how to write it. so far i been messing with this and i keep getting too many serial messages. and i cant figure out how to subtract the times and update a variable i think it would look somthing like this,

relaycurrent - relayprevious = timeelapsed, but i cannot get it to compile. if you cant already tell how much trouble im having figuring this out. im having ALOT i wish i had an example to look at

  if (autocontrol == 1 )
  {
   
      if ( h1 > 85.00 )
        digitalWrite(relay, LOW);
      relaycurrent = millis;
      Serial.println(millis());
      {
      if ( h1 < 81.00 );
      relayprevious = millis;
      digitalWrite(relay, HIGH);
      relayState = HIGH;
    }

You aren't following the basic rules of C++ syntax. You won't get anywhere until you learn them.

      Serial.println(millis());
      {
      if ( h1 < 81.00 );
      if ( h1 > 85.00 )
        digitalWrite(relay, LOW);
      relaycurrent = millis;
      Serial.println(millis());

Please tell me which lines of code will be executed
(a) if h1 > 85.00
(b) if h1 < 85.00

Do the answers match what you want to happen ?

what is wrong with my syntax. i have tried it so many ways i cant figure it out. someone is going to have to show me what i have wrong.

UKHeliBob:

      if ( h1 > 85.00 )

digitalWrite(relay, LOW);
      relaycurrent = millis;
      Serial.println(millis());



Please tell me which lines of code will be executed
(a) if h1 > 85.00
(b) if h1 < 85.00

Do the answers match what you want to happen ?

no they dont, i dont know how to write these if statements. i cannot figure out where im going wrong. please write that the way its suppose to be, the way i want it to run. i will learn mroe from that than reading the basics because ive been reading the basics and its getting me nowhere, even when i write them as suggested they dont work. if you could note next to my error and explain how and why this does and don't work ii would be very thankful

  if (autocontrol == 1 )
  {
   
      if ( h1 > 85.00 )
      {
        digitalWrite(relay, LOW);
      relaycurrent = millis;
      Serial.println(millis());
      {
      if ( h1 < 81.00 );
      relayprevious = millis;
      digitalWrite(relay, HIGH);
      relayState = HIGH;
    }
  }
  }
}

I gave you an example in post #3 how to use the brackets {}.... did you read it?

J-M-L:
I gave you an example in post #3 how to use the brackets {}.... did you read it?

i have wrote them like this

 if ( h1 > 85.00 )
      {
        digitalWrite(relay, LOW);
      relaycurrent = millis;
      Serial.println(millis());
      }
      if ( h1 < 81.00 );
      relayprevious = millis;
      digitalWrite(relay, HIGH);
      relayState = HIGH;
    }
  }

and it still blows up my serial screen with millis and turns realy2 off on off on off on then never shuts off millis no matter what

What's "millis" as opposed to "millis()"?

I haven't been following- have you got a variable called "millis"? If so that's a bit confusing; if not it won't complile.

And when you say "then never shuts off millis" do you mean your variable "millis" if you have one, or do you mean "millis()". In either case, what do you mean that it's never shut off?

my code compiles. it even works sorta. it comes on when its susppose to and shuts off when its suppose to. millis; is millis(): but millis keeps blowing up my screen. i dont know how to close the statements properly. im about done with it. ive wasted more time in front of this computer than i can afford

ive wasted more time in front of this computer than i can afford

You wasted ours then....

Last try... would this help you understand the concept:

const byte buttonPin = 2;
unsigned long startTime, stopTime, totalTime; // are initialized to 0 by compiler
boolean buttonPressed = false;

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  if ((buttonPressed == false) && (digitalRead(buttonPin) == LOW)) {
    // button is pressed
    buttonPressed = true;
    startTime = millis();

    Serial.print("start recording at ");
    Serial.println(startTime);

  } else { // button is not pressed, checking if this is a transition
    if (buttonPressed) { // button was pressed
      // button is released
      buttonPressed = false;
      stopTime = millis();
      totalTime += stopTime - startTime;

      Serial.print("stoped recording at ");
      Serial.print(stopTime);
      Serial.print(", duration was ");
      Serial.println(stopTime - startTime);

      Serial.print("Total cumulated pressed time is ");
      Serial.print(totalTime);
    }
  }
}

I see in an earlier post you also have "Millis" with a capital-M. Asking for confusal....

What do you mean millis is millis()?

"millis" must be a variable, and "millis()" is a function- they can't be the same thing. You can assign the current value returned by the millis() function to a variable called millis (or Millis for that matter) of course, but millis and millis() cannot be the same thing.

J-M-L:
You wasted ours then....

Last try... would this help you understand the concept:

const byte buttonPin = 2;

unsigned long startTime, stopTime, totalTime; // are initialized to 0 by compiler
boolean buttonPressed = false;

void setup() {
 Serial.begin(155200);
 pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
 if (digitalRead(buttonPin) == LOW) {
   // button is pressed
   buttonPressed = true;
   startTime = millis();

Serial.print("start recording at ");
   Serial.println(startTime);

} else { // button is not pressed, checking if this is a transition
   if (buttonPressed) { // button was pressed
     // button is released
     buttonPressed = false;
     stopTime = millis();
     totalTime += stopTime - startTime;

Serial.print("stoped recording at ");
     Serial.print(stopTime);
     Serial.print(", duration was ");
     Serial.println(stopTime - startTime);

Serial.print("Total cumulated pressed time is ");
     Serial.print(totalTime);
   }
 }
}

yes i think this is really going to help. THANKYOU! where can i find something to read about the +=>! of millis.

where can i find something to read about the +=>! of millis.

in the millis() documentation...

kenwood120s:
I see in an earlier post you also have "Millis" with a capital-M. Asking for confusal....

What do you mean millis is millis()?

"millis" must be a variable, and "millis()" is a function- they can't be the same thing. You can assign the current value returned by the millis() function to a variable called millis (or Millis for that matter) of course, but millis and millis() cannot be the same thing.

sorry man i'm so adhd i cant keep track of myself. if i wasn't i would have a much better learning experience. it makes me just as confused and aggravated as you guys get trying to work with me. but i don't just come straight here with every problem. i try to learn as much as i can on my own this is like the last resort.

J-M-L:
in the millis() documentation...

ive been to that documentation before but it don't mention the comparisons. or how to use division with it. under parameters it says none.

Nobody wants to chase you away....

You have to realise that millis, Millis and millis() are not the same thing.

millis with no () is a variable, and if you want a variable called millis you can do so, but it's confusing and you would have had to have declared it. That's why I asked if it compiled: if you have an undeclared variable millis, it won't compile.

And if you mean to get the value returned by the builtin function millis() with the (), then you need to say millis() not millis.

But when you post code snippets are you copying from your program or retyping?

To answer your very last post, millis() the function doesn't have parameters, it's a function that just return the current time since you fired up. (As distinct from say digitalWrite(5) which does have a parameter, namely the pin number.)