arduino syntax vs c++

hi, i'm very new to arduino and i'm trying to convert my c++ code into code that arduino can read.. it says "cin is not declared in this scope". so i was wondering what the arduino equivalent of cin is. thanks!

The Arduino is programmed in C++, you don't need to change any syntax to run C++ on Arduino. It's already in the right language.

But you do need to think for a second about what an Arduino is. It's just a little card with a processor on it. It doesn't have any screen or console, so there is no cout. Well, I guess technically there is, but it doesn't go anywhere. And it doesn't have any input devices so there is no cin. You have to come up with another strategy to get data into and out of the controller. Typically people use a serial connection between the Arduino and a PC.

Now if you want help with your specific code, you'll have to give us a chance to see it.

well for cout, i'm using serial.println, and i have a touch shield that'll be attached to the arduino later on

right now, i guess i'm depending on serial monitor to show me the input + output of my code

frustrasians: well for cout, i'm using serial.println, and i have a touch shield that'll be attached to the arduino later on

right now, i guess i'm depending on serial monitor to show me the input + output of my code

Exactly, so cout and cin aren't useful anymore. You'll be using Serial.print and Serial.read.

ah, okay thanks

this is basically what my setup looks like:

void setup() { Serial.begin(9600); tone (pin, 30, 800);

Serial.println("a number");

x = Serial.read();

Serial.println("another number");

y = Serial.read();

Serial.println("last number");

z = Serial.read(); }

but in my serial monitor, it shows all 3 character outputs w/o letting me input numbers first; how do i change the code to show "a number" and make it wait for my response to display the text "another number"?

See Robin2's serial handling basics tutorial.

And please, remember to use code tags when posting code.

Yeah, you ask the user for a number and then read from serial less than a microsecond later. In reality, the read would happen before the text you printed ever made it to the screen. You gotta give the user some time.

There is a Serial.available function so you can test whether or not the user has entered anything before you try to read from serial.

okay, i delayed by ten seconds and the serial monitor displays what i want....except for the fact that it doesnt display the numbers i input? i.e. i input 4, and it gives me 52

Hint: look at an ascii table. What's the ascii code for the character '4'.

www.asciitable.com

so if i want something to play for 4 secs, i'd have to input the ascii equivalent?

frustrasians: so if i want something to play for 4 secs, i'd have to input the ascii equivalent?

No, not at all. you just have to make a conversion from the ascii symbol to the actual number. It's simple math. Look again at the ascii codes for all the digits. What would happen if you subtracted 48 (usually written in this context as '0') from the number you got?

There is also the atoi function that can take a string of ascii characters and convert to an integer for times when you have more than one digit. And of course the blocking, but still occasionally used, Serial.parseInt() function.

A lot of this stuff is mentioned in Robin2's serial input basics tutorial thread.