Display a set of questions and store the answers as variables

I have a arduino nano that I created a small program for. when a button is pushed the following sequence starts:
play sound at a certain volume (y1) for a certain amount of time (x1)
stop the sound for a certain amount of time (x2)
play anouther sound at another volume (y2) for a certain amount of time (x3)

the program works but what I want to add now is a way for me to change these variables in the serial monitor.
I'm thinking it would be something like this:
open the serial monitor.
type "change"
print "set y1"
wait for a value to be typed in
store the input as y1
print "set y2"
wait for a value to be typed in
store the input as y2
print "set x1"
wait for a value to be typed in
store the input as x1.
print "set x2"
wait for a value to be typed in
store the input as x2.
print "set x3"
wait for a value to be typed in
store the input as x3.

and once the variables have been changed, when the button is pressed again the time and volume should follow the new variables.

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hello
post your sketch well formated and in code tags.

This is the sketch that I'm currently using I've not written anything that will activate the Serial monitor as I have no Idea how best to do that.

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// myDFPlayer setup
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
char input;

// TTL pinMode setup
const int sound = 4;
const int state = 5;
const int camera = 6;

// push button setup 
const int buttonPin = 2;
int buttonState = 0;

// setup variables
int volume1 = 10; // volume 1
int volume2 = 15; // volume 2
int time1 = 1000; // time 1
int time2 = 500; // time 2 
int time3 = 700; // time 3 

void setup() 
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);
 
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  digitalWrite(state, HIGH);
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
  myDFPlayer.volume(10);  //Set volume value. From 0 to 30
  
  //TTL pinmode set as output
  pinMode(camera, OUTPUT);
  pinMode(sound, OUTPUT);
  pinMode(state, OUTPUT);

  // button set as input
  pinMode(buttonPin, INPUT);
}

void loop()
{
 
  buttonState = digitalRead(buttonPin);
  digitalWrite(sound, LOW);
  digitalWrite(state, HIGH);

  if(buttonState == HIGH){
    //first delay 
    digitalWrite(camera, HIGH);
    myDFPlayer.play(5);
    myDFPlayer.volume(0);
    delay(100);

    //sound 1 time 1
    digitalWrite(sound, HIGH);
    myDFPlayer.volume(volume1);
    delay(time1);

    //delay time2
    digitalWrite(sound, LOW);
    myDFPlayer.volume(0);
    delay(time2);

    //sound 2 time2
    digitalWrite(sound, HIGH);
    myDFPlayer.volume(volume2);
    delay(time3);

    digitalWrite(sound, LOW);
    myDFPlayer.volume(0);
    delay(1000);
    digitalWrite(camera, LOW);
  }
}

Hello
take a view here.

Have a look at the various example for reading from Serial in Arduino Serial – Reading/Parsing each with their pros and cons.

Also your delay( ) may get in the way. BUT if the inputs are short (<64bytes) the SoftwareSerial RX buffer can hold the next input until you get around to reading it.

How to write Timers and Delays in Arduino covers removing delay( )s and Multi-tasking in Arduino covers how to re-structure your code as 'tasks' after your remove the delays from you 'linear' loop.

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