Need help to replace delay() with millis()

Hi everybody, I have written a code for my project. this code is working perfectly with delay(). But I want to replace it with millis(). I am a beginner in Arduino. i just learned all things online.
here I am posting my code, Can any one help me to replace the delay() in my code. I will we always thankful to you.

/........CODE............/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// A4=SDA , A5=SCL //
// motor M1 motor
int inM1 = 12;
// motor M2 motor
int inM2 = 10;
int inBZ = 11;        // Buzzer //
float potPin1 = 0;    // Speed //
float potPin2 = 1;    // Cotton Length //
float potPin3 = 2;    // Counter //
float potPin4 = 3;    // Hold Time //
float inval1 = 0;    float outval1 = 0;   // speed //
float inval2 = 0;    float outval2 = 0;   // length //
float inval3 = 0;    float outval3 = 1;   // counter //
float inval4 = 0;    float hld = 0;   float hld1 = 0;    // hold time //
float len = 0;       float outval5 = 0;
float cnt = 1;   // counter //
float spd = 1;       float wicks = 0;
float cwc = 0;
float ov3 = 1;
void setup() {
  Serial.begin(9600);    // set all the motor control pins to outputs
  pinMode(inM1, OUTPUT);  pinMode(inM2, OUTPUT);  pinMode(inBZ, OUTPUT);
  lcd.init();   lcd.backlight();
  lcd.setCursor(6, 0);  lcd.print("WELCOME");
  lcd.setCursor(4, 1);  lcd.print("To Our Team");
  lcd.setCursor(0, 2);  lcd.print("<<EXTREME MACHINE>>");
  lcd.setCursor(3, 3);  lcd.print("please wait...");
  delay (10000);
  inval1 =  analogRead(potPin1); inval2 = analogRead(potPin2); inval3 = analogRead(potPin3); inval4 = analogRead(potPin4);
}
void loop()
{
  lcd.init();   lcd.backlight();
  lcd.setCursor(0, 0);  lcd.print("<<EXTREME MACHINE>>");
  lcd.setCursor(0, 1);  lcd.print("Cnt");
  lcd.setCursor(10, 1);  lcd.print("Hld");
  lcd.setCursor(18, 1);  lcd.print("Sc");
  lcd.setCursor(0, 2);  lcd.print("Spd");
  lcd.setCursor(10, 2);  lcd.print("Len");
  lcd.setCursor(18, 2);  lcd.print("In");
  lcd.setCursor(0, 3);  lcd.print("Cwc");
  lcd.setCursor(10, 3); lcd.print("Twc");
  cwc = 1;
  for (cnt = 1; cnt <= outval3; cnt += 1) {
    inval1 =  analogRead(potPin1); inval2 = analogRead(potPin2); inval3 = analogRead(potPin3); inval4 = analogRead(potPin4);
    outval3 = map(inval3, 0, 1023, 10, 551); // counter//
    ov3 = outval3;
    outval1 = map(inval1, 0, 1023, 50, 500); //Speed//
    spd =     map(outval1, 50, 500, 10, 0); // speed display //
    outval2 = map(inval2, 0, 1023, 20, 110); // length//
    outval5 = map(outval2, 20, 110, 20, 900); // Adjust display of length here //
    len =     map(outval5, 20, 900, 200, 586); // length display  //
    hld =     map(inval4, 0, 1023, 0, 66);  // hold time//
    hld1 = hld * 10;
    // turn on M1 & M2 motor FOR SAME TIME LENGTH //
    digitalWrite(inM1, HIGH);  delay(000);
    digitalWrite(inM2, HIGH);  delay(outval2);       // time lenght of M1 amd M2 simultaniouslly //
    digitalWrite(inM1, LOW);   delay(000);
    digitalWrite(inM2, LOW);   delay(outval1);        // OFF time gap between M1-M2 and M2 //
    inval1 =  analogRead(potPin1); inval2 = analogRead(potPin2); inval3 = analogRead(potPin3); inval4 = analogRead(potPin4);
    // turn on M2 motor alone //
    digitalWrite(inM2, HIGH);  delay(outval2 + 50);     // RUN time of M2 alone  //
    digitalWrite(inM2, LOW);   delay(outval1);        // OFF time between M2 and M1-M2  //
    inval1 =  analogRead(potPin1); inval2 = analogRead(potPin2); inval3 = analogRead(potPin3); inval4 = analogRead(potPin4);
    if (digitalRead(inM1) > 0) ; {
      wicks = wicks + 1;
    }
    lcd.setCursor(4, 1);     lcd.print(ov3, 1);
    lcd.setCursor(14, 1);    lcd.print(hld1 / 10, 1);
    lcd.setCursor(4, 2);     lcd.print(spd, 1);
    lcd.setCursor(14, 2);     lcd.print(len / 100, 2);
    lcd.setCursor(4, 3);     lcd.print(cwc, 1);
    lcd.setCursor(14, 3);    lcd.print(wicks, 1);
    Serial.print(outval1) ;
    Serial.print('\n');
    Serial.print(outval2) ;
    Serial.print('\n');
    Serial.print(outval2 + 30) ;
    Serial.print('\n');
    inval1 =  analogRead(potPin1); inval2 = analogRead(potPin2); inval3 = analogRead(potPin3); inval4 = analogRead(potPin4);
    cwc = cwc + 1;
  }
  digitalWrite(inBZ, HIGH);  delay(100);
  digitalWrite(inBZ, LOW);   delay(25);
  digitalWrite(inBZ, HIGH);  delay(200);
  digitalWrite(inBZ, LOW);   delay(50);
  digitalWrite(inBZ, HIGH);  delay(300);
  digitalWrite(inBZ, LOW);   delay(000);

  delay(hld * 1000);
}

Welcome to the forum

Did you get a message suggesting that you use code tags when you posted your code ?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

not tested but you should get the idea, I hope.

int LEDSignalTimes[5] = {100, 25, 200,50, 300 };
unsigned long LedOnTime = LEDSignalTime[0];
unsigned long LEDOnTimePast =millis();
int ArrayTicker = 0;
boolean tick = true;

void loop()
{

if ( millis() - LEDOnTimePast >= LEDSignalTimes[ ArrayTicker ] )
{ 
 if ( tick )
 {
  digitalWrite(inBZ, HIGH);
 } else {
   digitalWrite(inBZ, LOW); 
 }
tick = !tick;
  ArrayTicker++;
 If ( ArrayTicker > 4 )
 {
   ArrayTicker = 0;
 }

 LEDOnTImePast = millis();
 }

}

Thank you for your kind suggestion.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.