Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Wait for an operator input  (Read 255 times)
0 Members and 1 Guest are viewing this topic.
Lancaster
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Mechatronic undergraduate
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to write a sketch which allows an operator to input two values (I'll be using these values later via two EasyDriver stepper drivers to move two stepper motors). I can't work out/find out how to get a sketch to stop looping and wait for an input. It needs to be an input of a number between 1 and 99.

I am quite new to this programming and may be missing something, but I've been through all the tutorials I can find and the Arduino Cookbook and can only find examples of input which are in the main loop. When I use these, it keeps going through the whole loop over and over whilst there's no input. So when I include Serial.print text to ask for an input, it just keeps writing this over and over.

I tried putting the input bit it in a separate function, but when there's no input it keeps returning to the main loop and back again, over and over  smiley-confuse

Any help anyone could give me with this would be greatly appreciated. I just can't think of a way of making it wait for the input.

Thanks  smiley
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 124
Posts: 4577
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at using Serial.available() to check for user input and have some means of indication to your program that input is complete, often a Carriage Return.

Have a look at the description of Serial.available() in the reference installed with the Arduino IDE, Google for examples of its use or search this forum for a multitude of posts on the subject.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Lancaster
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Mechatronic undergraduate
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. Much appreciated.  smiley
Logged

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: