Can't use millis() , only delay()

Elizandro:
About posting the code: Actually not very interested but if I knew that nobody would make copies of it I would. And also the same counts for the schematic/circuit.

This forum's all about sharing.

But if you can't post the whole code, you should at least post a complete sketch that exhibits the problems you have, but won't give away your trade secrets.

Not a whole lot of chance of you getting good (or even any) help if you can't at least do that much.

Not sure what you meant by the pot reading being a "time reference" earlier. If that was originally going to be the delay, then the equivalent of that in a millis() approach is what's usually called the interval or similar.

You check each time through loop() to see if the interval has expired, and act accordingly.The whole point is that since it never stops the sketch like delay() does, each time through loop() you can do other stuff.

But you really need to post more details (code, schematic) to get decent help.

Elizandro:
About posting the code: Actually not very interested but if I knew that nobody would make copies of it I would.

From what I've read, it's unclear to me what (if anything) would be worth copying.

Ok. Maybe I should just change the topic. Just like doing multiple tasks at a time, like:
https://forum.arduino.cc/index.php?topic=223286.msg1618246#msg1618246

I'm going to need to read two sensors and according to their value digital pin 8 is going to go HIGH or LOW. The delay was there to set a time to wait until it would go LOW and another delay to when it would go HIGH again.
In short words, a Motor Protector. Keeping a motor from burning when it's overloaded and to protect it from over and under voltage. The voltage are adjustable and also the over current with pots

Elizandro:
so I only flew over the posts (dif not read all of them) which is probably the cause of me not understanding.

I did not go to the trouble of writing my tutorial for aviators. Go back and walk through it slowly. Understanding the use of millis() is key for many Arduino situations. Success requires a little effort on your part.

...R

Haha, right!

Elizandro:
delay(VoltTime) was what I used. That was the point where everything freezes

About posting the code: Actually not very interested but if I knew that nobody would make copies of it I would. And also the same counts for the schematic/circuit.

Plz let me First think a bit about posting the code.

You have to be frigging kidding us.
Why should we help you!

Do you think your code and schematics are Gods gift to the community?

Please, let us first think a bit about helping you out.

Hey you are right! I'm building somethink that isn't going to be opensource and post questions about it into a opensource forum. Next time I post something into this forum I will firstly think 3 times... I apologize for wasting your time. :o

Don't worry it'll work out with my project(still a project).

Newbies, we learn from errors. Mine are because of not thinking enough before posting. Don't do the same...

Do you think a mechanic could fix a car, by just listening to the driver? "It squeals a bit when I put on the brake", or "It makes a knocking sound when I turn", or "it won't start", could the mechanic fix the car without even looking under the hood?

That is what you are asking us to do. It's purely a practical problem.

I agree with the OP. For me as a newbie delay is a lot easier to wrap your head around. While millis seems like a whole different beast.

But really OP!!???

If (OP code == 0) && (OPCIRCUIT ==0)
{
digitalWrite(OP, HIGH);
}

Definitely let the smoke in on this one

For me as a newbie delay is a lot easier to wrap your head around. While millis seems like a whole different beast.

I completely don't get that.... Using millis(), you are timing precisely the way you would doing the operation manually, with nothing but a wall clock to keep time:

  1. Mix the cake batter, and pour it into the pan.
  2. Put the pan in the oven, look at the wall clock, and note the time.
  3. Note that the cake takes 35 minutes to bake.
  4. Periodically, look at the wall clock. Subtract the time you put the pan in the oven from the current time.
  5. Has the cake been in the oven for 35 minutes yet? If yes, then take the cake out of the oven, and turn off the oven. If no, then go do something else for a few minutes, then come back and check again.

What could be simpler? Literally, a 6 year-old can do it!

Regards,
Ray L.

Maybe just easier to write. I don't have any prior programing experience.
So maybe since delay was the first timer I learned it made it easier. I don't know.
And most tutorials for blink use delay.. how would one write the following using Google millis?

DigitalWrite LED HIGH
Delay 1000
DigitalWrite LED LOW
Delay 1500

Repeat x amount of times.

I know that millis is pretty much superior but in the learning section or ide examples it seems like delay gets thrown around a lot.

delay(...) is easy, but as soon as you want to blink two LEDs at different rates or do something while you wait, millis() is better.

My suggestion is to learn the millis() way now and avoid delay(...). Finite State Machines are helpful also.

LandonW:
how would one write the following using Google millis?

DigitalWrite LED HIGH
Delay 1000
DigitalWrite LED LOW
Delay 1500

Repeat x amount of times.

I have no idea what "using Google millis" means, but have a look at #6 here from yesterday which has the on- and off-intervals different. As to the number of repeats, pretty sure you could figure out a counter, ++'d each time it blinks. At the same time as you check for the interval to have expired, check if the counter is still in range and do the blink or not. (But don't do it with a for() or anything else that blocks.)

I know that millis is pretty much superior but in the learning section or ide examples it seems like delay gets thrown around a lot.

I think it's a huge shame that the Blink with delay() example is there at all, since it seems to cement a certain approach in our minds and then Blink Without Delay seems like a major leap. As shown in the cake example, Blink with delay() is not the way things we do things irl, Blink Without Delay is. Yet the Blink sketch, being so easy, is where we start and then we're screwed. It then becomes a huge leap to unlearn that, only to try to learn to code something they way we would do it irl anyway.

delay() has its place. If you leave it out of the code below for example, the eeprom won't be written, and it would be crazy to do this with a millis() approach although it blocks for 5ms.

// below is the write function, untouched from playground, except ***
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(rdata);
  Wire.endTransmission();
  delay(5);  // ***

LandonW:
how would one write the following using Google millis?

DigitalWrite LED HIGH
Delay 1000
DigitalWrite LED LOW
Delay 1500

Repeat x amount of times. .

I don't know why you have hi-jacked this Thread instead of starting your own. And my guess is that you have not read the whole Thread carefully - and in particular the link in Reply #3 which illustrates how to use millis()

...R

Sorry guys, I didn't realize Google got in there, that's weird. I am on a tablet and it's autocorrect is horrible.

Nothing was meant to be hijacked I was just expressing an opinion on what's easier to write as a newbie.

LandonW:
Sorry guys, I didn't realize Google got in there, that's weird. I am on a tablet and it's autocorrect is horrible.

Nothing was meant to be hijacked I was just expressing an opinion on what's easier to write as a newbie.

Hmmm so now you have me wondering what was there that became "Google" :slight_smile:

It is easier to write, but you get what you pay for. As soon as you want to do anything that won't work when blocked (like simply reading a button on a pin during either the led on or off part), you have to graduate to millis(). That includes a change of approach where you have to do some rearrangement. It's not just a simple matter of changing delay(myInterval) to millis(myInterval) as if millis() was a magic non-blocking version of delay().

i think google had a close relationship to the few beers i had