Why won't the serial monitor stop for input? Is it stuck in an infinite loop?

This is my third arduino project, and I am using the serial monitor for the first time. The project is meant to ask the user for the power and amount the time that the DC motor is to run at. Then the user presses a button and the motor runs with their defined inputs. I know that my set up isn't the issue, it's the code.

When it comes time for the user defined values, the program doesn't stop for input, it just displays the Serial.print statements over and over again until I unplug my Uno.

What am I doing wrong? I am fairly new at this, and do not have much of a background in programming.

// ******* GOAL *******

// run a motor at a power
// and time specified interactively 
// over the serial connection, 
// after a button is pressed

// ******* DEFINITIONS *******

#include <AFMotor.h>

// motor number 3
AF_DCMotor motor(3);

//UNCHANGING VALUES 
// button pin
const int Button = 9; 

//VARIABLES 
// the current button reading         
int buttonState;    
// Last run’s reading             
int lastButtonState = LOW;    

// Using unsigned long to prevent overflow 
// the last time toggled
unsigned long lastDebounceTime = 0;  
// debouncing time minimum delay
unsigned long debounceDelay = 10;  

int powerChar = Serial.read();
int timeChar = Serial.read();

//******* Start the program *******

// ******* SETUP *******
void setup() {

   uint8_t i;

  // establich communication
  Serial.begin(9600);

  // button is an input
  pinMode(Button, INPUT);

} // end setup

// ******* THE DOING *******
void loop() {

  // go to input function
  askForUserInput();

// ******* DEBOUNCING *******
  // read the state of button
  int reading = digitalRead(Button);

  // if Last button state is not equal to the reading
  // make timer equal time of this run
  if (reading != lastButtonState) {
   
    // setting debounce timer using millis 
    // millis is built in timer. records run time in milisecondss
    lastDebounceTime = millis();
  } // end of debounce condonitions

// ******* UPDATING *******
// if the millisecond counter is longer than the last debouncing time, 
// but greater than the debouncing delay, update the state changes
  if ((millis() - lastDebounceTime) > debounceDelay) {

    // let the button state update
    if (reading != buttonState) {
      // read the button state
      buttonState = reading;

// ******* MAKE THE MOTOR GO *******
      // Turn motor on with user specifications, if button pushed
      if (buttonState == HIGH) {
        
       // go to the motor control function
       motorGo();
         
      }   // end if button pushed

    }   // end updating button state
    
  }  // end updating if statement 
  
  // save state for next reading
  lastButtonState = reading;

  // stop the motor
  // motor.run(RELEASE);
  
  // restart the loop
  Serial.println("LETS GO AGAIN");
  
  // pause for a second before going again
  delay(1000);
  
}   // end of iteration

// ******* USER DEFINED FUNCTION *******

// function for data interaction
void askForUserInput() {

// ******* ASK QUESTIONS *******
    // statement for requested information
    Serial.println("Please Enter the following information to run the motor.");
    Serial.println();

  // User defined variables
    // define the power setting
    Serial.println("What power do you want to motor to run?: \'");
    Serial.println ("Power can range 1-255.");

    Serial.write(powerChar);
    Serial.println();
    
  // define the time setting 
    Serial.println("How long would do you want to motor to run?: \'");
    Serial.println("Time will be mesaured in miliseconds.");
  
    Serial.write(timeChar);
    Serial.println();
 
  // instruct user to press the button
    Serial.println( "Now please press the button."); 
}

void motorGo() {

   // testing reasonability of input
   if (powerChar <= 255 && powerChar != 0) {

     // run motor with user definition 
     motor.setSpeed(powerChar);
          
     // user defined time
     delay(timeChar);      

    } // end update the motors from user

    // if too much power defined
    if (powerChar > 255 || powerChar <= 0) {

      // send correcting information
      Serial.println( "THAT IS TOO HIGH OF A POWER!");
      Serial.println( "POWER CAN ONLY RANGE 1-255!");
          
     } // end correction
         
} // end motorGo

You have a fundamental misunderstanding. Try reading this post Serial Input Basics - updated - Introductory Tutorials - Arduino Forum

I think it will help you

for instance in

void askForUserInput() {

// ******* ASK QUESTIONS *******
    // statement for requested information
    Serial.println("Please Enter the following information to run the motor.");
    Serial.println();

  // User defined variables
    // define the power setting
    Serial.println("What power do you want to motor to run?: \'");
    Serial.println ("Power can range 1-255.");

    Serial.write(powerChar);
    Serial.println();

shouldn't the program let the user input the value for power at Serial.write(powerChar); ? It just keep moving through the loop.

Am I wrong? Is that not the way to receive user input?

No. Read the post I linked.

TKall:
You have a fundamental misunderstanding. Try reading this post Serial Input Basics - updated - Introductory Tutorials - Arduino Forum

I think it will help you

Sorry! I wasn't trying to ignore you, I wasn't aware that they was a limit for how many posts you can make in a 5 minute period.

But I will check it out!

No worries.

I've worked through that link a few times over the years: I don't do serial input too often so every time I need to, I have to read the tut again- it's very good.

But I don't think it explicitly covers the case of prompting for input with a pause, which would be nice.

(What would be even nicer, would be something like BASIC's INPUT statement which prompts, pauses and takes the value in one fell swoop :wink: )

But I don't think it explicitly covers the case of prompting for input with a pause, which would be nice.

Sure it does, you just have to think about it the right way. State machine, for example.

TKall:
Sure it does, you just have to think about it the right way. State machine, for example.

In the context of my post, "it" clearly refers to the tutorial, which doesn't explicitly cover how to do that as far as I can remember. "It" there is not Arduino at large: yes, it can be done, I didn't say it couldn't.

I didn't actually mean "pause", but never mind, I cba to try explain what I meant. Not important in the grand scheme of things.

I know as much about millis()-based delay()-less timing and state machines as just about anyone on this site; my bad was not expressing myself properly there, sorry for that.

I'm gone: won't trouble anyone again.

There is a simple user-input example in Planning and Implementing a Program

Note how the question and answer are separated - in the style mentioned in Reply #11

...R