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!