A question about serial data input

So, real quick...I am building a gantry robot that will dip a test article into a tank of cold water, then into a tank of hot water, then back to cold etc. I was hoping to have a user friendly interface...such that the arduino would ask for the user to input the number of cycles (over serial), and then wait for the user to send a prompt to start (again over serial). Once it received both the number of cycles and the prompt to start, the code should go into a loop of dipping back and forth X number of times...X being the number entered through serial at the beginning. I wrote up a quick test program that is supposed to wait for the user to input a number through the serial port, and then that number becomes the delay for a blinking LED. The issue is, unlike other examples of this sort of thing, I need the serial data to only be received once at the start of the program, hence why I put it in the setup function. However, I get an error message in the void loop saying that stepperspeed was not defined in this scope. I know that I am doing something wrong in my approach to this, does anyone have any suggestions on either what to do, or where to look?

Here is the test program:

void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
getdata();
}

void loop() {
displaydata();
}

void getdata(){

char buffer[] = {' ',' ',' ',' ',' ',' ',' '}; // Receive up to 7 bytes
Serial.println("please enter the max speed of stepper");
while (!Serial.available()); // Wait for characters
{
Serial.readBytesUntil('n', buffer, 7);
unsigned int stepperspeed = atoi(buffer);
}}

void displaydata(){
digitalWrite(13, HIGH);
delay(stepperspeed);
digitalWrite(13, LOW);
delay(stepperspeed);
}

Thanks!

You declared stepperspeed inside getdata(). Move the declaration (where you give it a type) outside all functions so it is global. Then you can set the value in one function and read the value in another.

Here is the test program:

#7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

Thank you for the suggestion, Morgan. Fixed the problem :slight_smile: As I am sure you can tell, I am pretty new to Arduino...

zoomkat, I apologize, I should have gone through that in detail before posting. Will try to be better about that in the future.