Can someone show me the input command for arduino?

ok so basically what i want to do is ask a question in the program. for example i want to say “enter a number”, so then you would enter a number into the program and hit enter. how do i do that ? what is the input command for arduino???

im basically asking in c++ its cin>> so wat is it in arduino??? im new to this.

Since the arduino is basically the bridge between the computer and the physical, where / how do you want to ask for input? what kind of input?
Do you want to ask a computer to provide the input over serial?
Show the question on a LCD and let them ‘type’ (in what form?) the input?

If this was on a computer, I’d expect you to mean a generic command line output and input method, but with the arduino, you have so many more options, that it might be a bit sad to assume you mean the same generic command line output and input method, since it wouldn’t really involve your little arduino :stuck_out_tongue:

ok so heres the problem. i have to do a project for school. i have to build an elevator and use the arduino to program the elevator. it starts at the 1st floor and then i have to choose what floor i want to go to. so the person would type in 3 or 4 or something in the computer and then the elevator would go up to the 3rd or 4th floor. its that simple. can someone just tell me the command to do that?

What computer? I thought we were talking about Arduinos here. Does your Arduino have a keyboard attached?

How many floors are you simulating? If it's only like 5, just attach 5 switches to the Arduino. Real elevators don't have keyboards. They have call buttons on each floor.

i want to say "enter a number", so then you would enter a number into the program and hit enter.

Arduino doesn't have any input commands that are that powerful; it exists at a rather more primitive level. You can use "Serial.read()" to read a single character, but you have to assemble the characters into lines and numbers on your own.

You could look at some of the existing libraries, like http://www.arduino.cc/playground/Code/Messenger

so there is no way of getting this done not even with the serial monitor?

Quite easy with the serial monitor,but you were talking about a keyboard which the arduino doesn't have, it was never designed to be tethered to a computer - do a little reading on serial :

http://arduino.cc/en/Reference/Serial

ok so here is what i basically have so far. im just trying to build a small simple elevator, not a complicated realistic one. basically the elevator starts at the 1st floor and then the user would input the floor he wants to go to and then the elevator would go either up, down, or stay put. thats all. i am getting this error.

In function ‘void loop()’:
error: expected identifier before ‘(’ token

int currentfloor = 0;
int df = 0;               // destination floor
int pin10 = 10;         // pin 10
int pin9 = 9;          // pin 9
int pin3 = 3;              // pin 3
int val;

// START
void start() {
Serial.print("current floor = ");
Serial.println(currentfloor);
Serial.print("enter destination floor: ");
df = Serial.read();
}

// UP
void up(){
  while (currentfloor != df) {
    val = digitalRead(pin3);
    digitalWrite(pin10, LOW);
    delay(700);
    while (val != 0)
      digitalWrite(pin10, LOW);
    while (val != 1)
      digitalWrite(pin10, LOW);
    currentfloor=currentfloor+1;
    Serial.print("current floor = ");
    Serial.println(currentfloor);
  }
  delay(700);
  digitalWrite(pin10, HIGH); 
}

// DOWN
void down(){
  while (currentfloor != df) {
    val = digitalRead(pin3);
    digitalWrite(pin9, LOW);
    delay(700);
    while (val != 0)
      digitalWrite(pin9, LOW);
    while (val != 1)
      digitalWrite (pin9, LOW);
    currentfloor=currentfloor-1;
    Serial.print("current floor = ");
    Serial.println(currentfloor);
  }
  delay(700);
  digitalWrite(pin9, HIGH);
}

void setup(){

Serial.begin(9600);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(pin3, INPUT);
}

void loop(){

val = digitalRead(pin3);

void start();

if (df > currentfloor) && (df < 9)
void up();
if (df < currentfloor) && (df < 9)
void down();
if (df == currentfloor)
void start();

}

oh wait i fixed the problem. it was a simple newbie problem. ok but it compiles now. so diff question, sry for so many questions btw. will the serial.read(); allow me to input a number? im not understanding the way serial available / read works. thx.

serial.available returns the number of characters it has received, that are ready to be read. serial.read reads a character that it has available, it will wait for one to become available if no character is available (see available above).

if (Serial.available() ) {
      serinput = Serial.read();
      if ((char)serinput == 'A' ){ 
       // do something here if A is sent;
      }  
//........
}

Tip ;)

i understand what you are saying when you input a letter but when i input a number such as 5 , it returns something like 43 or 52. not the number i actually inputted.

ok so the closest solution ive come to reading my input is subracting my input by 48 lol. that seems to work.

but when i input a number such as 5 , it returns something like 43 or 52.

When you type ‘5’, this is sent over the serial line as the ASCII code 0x35 or 53 decimal.
Subtracting 48 (0x30 the ASCII code for ‘0’ (zero)) converts the ASCII code to the decimal digit.

So, send a ‘9’, ASCII code 0x39, subtract 0x30, result 9.

@Imahilus

serial.read reads a character that it has available, it will wait for one to become available if no character is available

Nope. This is not true. If there is no data to read, Serial.read90 does not wait. It returns immediately, returning a value of -1.

if (Serial.available() ) {
      serinput = Serial.read();
      if ((char)serinput == '1' ){
       // do something here if 1 is sent;
      }
//........
}

That should work with numbers, char() just tells it to interpret it as a character rather than its ASCII value. but subtracting 48 from the ASCII value gives the number as a numerical value. Both equally good for what you're doing.