Need help on my Project [PLEASE!]

I was hoping someone can shed me some light on my project.
I’m really stuck, I’ll be posting my sketch and hope someone will
give some example out of my sketch, advance thanks.

Lists of my questions:

// how can I make this like those “BlinkWithoutDelay” function? I understand how it works, but I don’t know how. [My Question]

//how can I make both of them run at the same time with different delays? [My Question]

//how to make an array out of my sketch?

// how can I make that it will wait until all of the delays are met before the “initialize();” start? [My Question]

It is commented inside my sketch thanks for your time
hoping for replies.
[sorry old sketch already updated new one, please help ^^]

Please_Help_Me2.ino (8.4 KB)

You will probably need to write this as a State Machine where you keep track of what you were in the process of doing and check each time through loop() if it is time to go on to the next step.

See this forum thread: Demonstration code for several things at the same time

thanks for the reply, its just that I can't understand blinkwithoutdelay function, I only understand its purpose.

I've had a look at your sketch. It's rather a pity that it has got so big before you started worrying about the use of the delay() function.

Rather than try to fix all of that at once I suggest you write a short program (maybe just a small part of the project - without any LCD stuff - just show values on the Serial Monitor) and work out how to use millis() to manage the timing as illustrated in the link @johnwasser has given you.

If you run into problems with your short code then post your best attempt and we will try to help.

And, please, don't change code or posts you have already made (apart from correcting errors) because the Thread won't make sense if comments refer to something that is no longer there. Just put new code in a new post.

The idea behind BWoD is very simple.

  • start something and record the time ( millis() ) when it starts
  • then regularly check the difference between the latest value of millis() and the value at start time
  • when the difference has reached the desired level do whatever should happen then.

For example (pseudo code)

void loop()
   if (buttonPressed == true) { 
       startTime = millis();
       // turn on LED
   }
   if (millis() - startTime >= desiredInterval) {
       // time has expired
       // turn off LED
   }
}

...R

The following snippet taken from your own code may help to illustrate the concept

void Dispensing()
{
  if (dispensingInProgress == false && dispensingRequired == true) {
     digitalWrite(MixerDispMotor,HIGH);
     dispenseStartMillis = currentMills;
     dispensingInProgress == true;
     dispensingRequired = false;
     return;
  }
  // delay(6000);   //Same again "BlinkWithoutDelay" Funtion. 
  
  if (currentMillis - dispenseStartMillis >= 6000) {     
     digitalWrite(MixerDispMotor,LOW);
     // rest of code
     dispensingInProgress =  false;

   }
 }

I am assuming that the variable currentMillis is set equal to millis() at the start of loop(). It means that all the timing uses the same value.

Note that I have added a new global variable dispensingInProgress to record the state of the process so that the different parts of the code know when to operate.

And I have another new variable dispensingRequired which will be set elsewhere in the program when you want something dispensed. This allows the function Dispensing() to be called on every iteration of loop() so that the timing can work.

You can probably see that switching from delay() is not trivial. However using millis() is not difficult if you plan the project that way from the start.

...R

Thanks for the help I'll be posting updates soon, glad someone helped. .

giogacang: thanks for the reply, its just that I can't understand blinkwithoutdelay function, I only understand its purpose.

You might find this video useful.

Demonstration code for several things at the same time

I think this is what i've been looking for, but I can't seem to open the link. Can anyone else open it or is it just me?

@ Thomas499 the link is opening like this ::http://%22http//forum.arduino.cc/index.php?topic=223286.0%22

just cut the http://%22http// and try to reload . with forum.arduino.cc/index.php?topic=223286.0" only

Thomas499: I think this is what i've been looking for, but I can't seem to open the link. Can anyone else open it or is it just me?

This should be ok...

JimboZA:
This should be ok…

The same problem happened to me yesterday because I took my eye off the ball and used the silly wysiwyg editor when adding a link. I’ve never had a problem with the source-view.

…R

waaa.. too many reply thank you so much. Sorry I'm really new to this kinds of stuff to many things I still don't understand I've build that code with help.

really thanks.

Going on with what Robin gave you.

void Margarita()
{
  static unsigned long currentTime, prevTime;
  static bool Start = false, Done_1, Done_2;
  
  if(Start == false)
  {
    digitalWrite(Liq1Motor2, HIGH); 
    digitalWrite(Liq2Motor2, HIGH);
    prevTime = millis();
    Start = true;
    Done_1 = Done_2 = false;
  }
  
  if(Start == true)
  {
    currentTime = millis();
    if(currentTime - prevTime >= 3550)
    {
      digitalWrite(Liq1Motor2, LOW);
      Done_1 = true;
    }
    if(currentTime - prevTime >= 2340)
    {
      digitalWrite(Liq2Motor2,LOW);
      Done_2 = true;
    }
  }
  
  if(Start & Done_1 & Done_2)
  { 
    Start = Done_1 = Done_2 = false;
    initializing();
  }
  //how can I make both of them run at the same time with different delays? [My Question]
  //how to make an array out of my sketch?
  // how can I make that it will wait until all of the delays are met before the "initialize();" start? [My Question] 
}