Play modes Without Delay in DF Player

#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(17, 16); // RX, TX
DFPlayerMini_Fast player1;
const byte Pin1 = 22;
const byte Pin2 = 23;
const byte Pin3 = 24;
const byte Stop = 48;
boolean readValue22;
boolean readValue23;
boolean readValue24;
const byte LockInd = 47;
void setup() {
  // put your setup code here, to run once:
  pinMode (LockInd, OUTPUT);
  digitalWrite(LockInd, LOW);
  pinMode(Pin1, INPUT_PULLUP);
  pinMode(Pin2, INPUT_PULLUP);
  pinMode(Pin3, INPUT_PULLUP);
  pinMode(Stop, INPUT_PULLUP);
  mySerial1.begin(9600);
  if(player1.begin(mySerial1, false))
  {
  player1.volume(22);
  }
}

void loop() {
  if(!digitalRead(22))
  {
    player1.play(103);
    while(!digitalRead(22));
  }
  if(!digitalRead(23))
  {
    player1.play(103);
    delay(800);
    player1.play(103);
    while(!digitalRead(22));
  }
  if(!digitalRead(24))
  {
    delay(400);
    player1.play(103);
    while(!digitalRead(22));
  }
  if(!digitalRead(48))
  {
    player1.stop();
  }
  

}

In above simple DF Player configuration
I am applying 3 types of play assigning it to 3 inputs

For first mode with input 22
It plays the file from beginning to end simply like it always go through as usual

For second mode with input 23
Firstly the file starts playing from very beginning and after 800 micro seconds of the play it again starts playing the file again from very beginning

For third and last mode of play with input 24
When the button gets pressed , the file starts playing after a delay of 400 micro seconds (from the very beginning as usual)

This type of configuration is working very well , no issues
But now, I want to remove the delay and want to operate it as usual

In short I want to run the program without delay
as we find projects like blinking LED without delay.

Please guide :blush: !!!!!!

The delay function delivers millisecon delay, not micro....
What do You want the controller to do during the delay time?

You do that in three places, two of which seem like mistakes.

Also, as @Railroader pointscout, you aren't talking about microseconds. delay() works with milliseconds. Some little difference…

a7

OK milliseconds . . .DONE !!!!!

The code you want is here

#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(17, 16); // RX, TX
DFPlayerMini_Fast player1;
const byte Pin1 = 22;
const byte Pin2 = 23;
const byte Pin3 = 24;
const byte Stop = 48;
boolean readValue22;
boolean readValue23;
boolean readValue24;
const byte LockInd = 47;
void setup() {
  // put your setup code here, to run once:
  pinMode (LockInd, OUTPUT);
  digitalWrite(LockInd, LOW);
  pinMode(Pin1, INPUT_PULLUP);
  pinMode(Pin2, INPUT_PULLUP);
  pinMode(Pin3, INPUT_PULLUP);
  pinMode(Stop, INPUT_PULLUP);
  mySerial1.begin(9600);
  if(player1.begin(mySerial1, false))
  {
  player1.volume(22);
  }
}

void loop() {
  if(!digitalRead(22))
  {
    player1.play(103);
    while(!digitalRead(22));
  }
  if(!digitalRead(23))
  {
    player1.play(103);
    delay(800);
    player1.play(103);
    while(!digitalRead(23));
  }
  if(!digitalRead(24))
  {
    delay(400);
    player1.play(103);
    while(!digitalRead(24));
  }
  if(!digitalRead(48))
  {
    player1.stop();
  }
  

}

Now we need to omit delay and make it functioning as it is without delay
!!

Vital part is this one only

if(!digitalRead(23))
  {
    player1.play(103);
    delay(800);
    player1.play(103);
    while(!digitalRead(23));
  }

where we want to remove delay !!

As already pointed out, more changes are needed. The while would effectively omit what millis timing could give.
What is the big picture for the project.

Just to introduce features as a purpose to learn bit more complex things.
An idea just came in mind and I started with this one nothing else . .

OK if we remove this while part
then how to proceed with rest of things
What's there to add more

Look for the "state change" way. Switch/case constructions are good for handling sequencies like: play, wait, play.

What's the point of giving a pin a name, if you don't use it?

It was already there with several working scripts so the stream is as usual going on with mentioned things

That is not a matter which may effect the presence or absence of delay I guess !!

I think that means "time for a tidy-up" before it gets any worse.

Yes yes yes State change
In fact I am working with the state change scripts

After a few moment I ll post it too

For now the building base code for state change I am using is something like this

signed long Pin1 = 22;
signed long Pin2 = 23;
byte Led1 = 11;

// boolean ledstate = false;
int ledState = LOW;

unsigned long previousMillisA = 0;
const long intervalA = 500;

void setup() {
  // put your setup code here, to run once:
pinMode(Pin1, INPUT_PULLUP);
pinMode(Pin2, INPUT_PULLUP);
pinMode(Led1, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
unsigned long currentMillisA = millis();
if (currentMillisA - previousMillisA >= intervalA) 
{
    previousMillisA = currentMillisA;

    if(!digitalRead(Pin1))
    {
      if (ledState == LOW) 
      {
        ledState = HIGH;
      }
      else 
      {
        ledState = LOW;
      }
        digitalWrite(Led1, ledState);
    }
    else
    {
      digitalWrite(Led1, LOW);
    }
}
}

Is this kind of thing you are talking about ????

You're really going to have to talk us through this one.

#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(17, 16); // RX, TX
DFPlayerMini_Fast player1;
const byte IN1 = 23;
boolean readValue23;
void setup() {
  pinMode(Pin1, INPUT_PULLUP);
  mySerial1.begin(9600);
  if(player1.begin(mySerial1, false))
  {
  player1.volume(22);
  }
}
void loop() {
if(!digitalRead(23))
  {
    player1.play(103);
    delay(860);
    player1.play(103);
    while(!digitalRead(23));
  }
}

Does that even compile?
Why are you posting this stuff?

tidy work
and ya everything is working very well

Just I want to apply a different method as per target of this thread

I prepared this kind of various code as per requirement, an year ago
No issue with working

And ya switch case I am applying in so many ways

Now as you said this play wait etc
Ya that is also possible , le me try with that !!!

I suggest changing this part. You only read Pin1 at those intervals. Do that reading on top of loop and save is as Pin1Input... Then use Pin1Input down in the logic.

We used that method in an industrially used machine for the CAN bus communication.... Lots of tasks running.....

O O O I see . . . Industrial use :open_mouth:

Yaaaa that really helped me a lot with several designs and very exclusive than so many applied concepts !!

A great info it is !!!