Pages: [1]   Go Down
Author Topic: C++  (Read 4334 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
C++
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I'm pretty new to the Arduino world.

I'm using using an arduino uno board and I want to interface it to a Borland C++ program. Basically I want one of the pwm ports to ouput a certain voltage if a variable is one value and another voltage if that variable is another. I wrote the code to do this with the arduino software. So do I upload that code to the board then use the serial.read and serial.write commands?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So do I upload that code to the board then use the serial.read and serial.write commands?
You have the order backwards, but the concept right.

Whatever the PC sends to the serial port, the Arduino reads using Serial.available() and Serial.read(). When the Arduino wants to send some data back, it uses Serial.write(), Serial.print(), and/or Serial.println().

Be sure to read up on the difference between Serial.print and Serial.write(), so you know when to use each one appropriately.

Also, make sure you understand that the Arduino reads one byte/character at a time. If the C++ application sends 27 as a string, the Arduino will read that as '2' and '7', not as the number 27.
Logged

Pages: [1]   Go Up
Jump to: