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

Hello Arduino Community,

I've been working on a project for a couple weeks now.

I have googled around but without an appropiate answer to my problem.

Components: 4 Potentiometers and 1 to adjust brightness of LCD, 1 LCD, 1 Pushbutton with pulldown resistor and of course an Arduino uno.

2 potentiometers are used to adjust a value and that value is displayed in the LCD and the other one(1) to adjust a time between 30 seconds to 5 minutes. The last one to adjust time between 1 second to 10 seconds.

Everything works fine without the timing (delay() ) events. But when I enable that, the arduino freezes/ gets stuck in the delay() function.

When pressing the button I just get a Menu that shows sensor data for about 10 second (here I also used delay() but I don't think that's a problem...).

Any help please! :confused:

A newbie with 7 posts should know how to post code and should know that there is little help without code being posted.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.
  5. Please provide links to any libraries that are used
    (look for statements in your code that look like #include ). Many libraries
    are named the same but have different contents.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

millis() and delay(...) work fine for me.

Elizandro:
Everything works fine without the timing (delay() ) events. But when I enable that, the arduino freezes/ gets stuck in the delay() function.

Yes. That's what delay() does.

If you need your sketch to display something for 10 seconds and also at the same time to be able to respond to events like button presses during those 10 seconds, then - well - you are going to have to learn to do things the arduino way, using millis() and state machines. There's no way around this.

Grok the "blink without delay" example.

Read "Several things at the same time".

Thanks PaulMurrayCbr for the link. It is a bit confusing at some points of the conversation but I'm going to check out the Nick Gammon site.

And my Arduino IDE keeps telling me "previously defined here", but evreything worked before that. I think that is the problem why I can't use the millis functon nor the button.

Post the code that produces that error

Me again. The problem of "previously defined here" is now fixed. I had somehow a few copies in the same folder and had to remove those. Here is a link that helped me to fix that problem:

https://forums.adafruit.com/viewtopic.php?f=25&t=26727

Since that is now fixed I'm going to try thr code with millis() again and then come back...

Elizandro:
Since that is now fixed I'm going to try thr code with millis() again

You won't be disappointed in the long run: understanding it will be time well spent.

<
if (Voltage_Sensor > Low_Voltage) {
digitalWrite(Cutoff, HIGH);
millis(VoltTime);
digitalWrite(Cutoff, LOW);
}else{
digitalWrite(Cutoff, HIGH);
}

That is the code and here comes the error message.

C:\Users\eliza\Documents\Arduino\Folder\Sketch_folder\Sketch.ino: In function 'void loop()':

Sketch:81: error: too many arguments to function 'long unsigned int millis()'

millis(VoltTime);

^

In file included from sketch\Sketch.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:132:15: note: declared here

unsigned long millis(void);

^

exit status 1
too many arguments to function 'long unsigned int millis()'

millis(VoltTime);

That's not how you do it.
millis() returns the number of milli seconds since the last powerOn/reset.
millis() takes no argument.

.

Read this:

VoltTime is data read from a pot. So how do I write the code, so its going to use the pot as the "time reference"?

millis() doesn't take any arguments as in millis(VoltTime).

millis() starts running at power up or reset, and returns the time in milliseconds, into a variable.

So you use it to record say the time at which something happened, like:

startTime = millis();

Then later on when millis() has moved on some, you can see if that's long enough for what you wanted to be happening:

if (millis()-startTime >= someInterval) //this is an updated mills() of course
{
    //do things
}
else
{
    //do otherthings
}

Elizandro:
Thanks PaulMurrayCbr for the link. It is a bit confusing at some points of the conversation

If you tell us what parts you find confusing I will try to help.

...R
Several Things at a Time

Well maybe I guess because there are case where the topic changes a bit along the topic.

But back to my problem. It is very important not to use delay() or delayMicroseconds(), since it pauses programm and the Arduino should read two sensors at the same time and put digital pin 8 High or LOW according to the sensor values. It is impossible for it to stay in that delay

Elizandro:
Well maybe I guess because there are case where the topic changes a bit along the topic.

Sorry. I don't understand. (I assume you responding to Reply #13)

...R

Hi,
I think you need to tell us exactingly what you have and what you want to do.

Do it in point form so it is clear and concise.
Then read it back to yourself then post it.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Please post your entire code.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I know it is a lot, but you have everything with you and know what you want, we don't.

Thanks.. Tom... :slight_smile:

Perhaps instead of this

  millis(VoltTime);

you intended this

  delay(VoltTime);

[not that I would ever recommend using delay(...) except in programs where one doesn't want to do anything else and never will].

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.

Robin2:

I mean coding style and switching code. I got bored of that since I was searching for more posts that could indirectly answer my questions and so I only flew over the posts (dif not read all of them) which is probably the cause of me not understanding.