Forum 2005-2010 (read only)
Syntax & Programs
(Read 5092 times)
Jan 24, 2011, 12:22 am
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?
Seattle, WA USA
Jan 24, 2011, 12:40 am
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.