Hardware Reference
In-Depth Information
{
rval = Serial.parseInt(); //First valid integer
gval = Serial.parseInt(); //Second valid integer
bval = Serial.parseInt(); //Third valid integer
if (Serial.read() == '\n') //Done transmitting
{
//set LED
analogWrite(RED, rval);
analogWrite(GREEN, gval);
analogWrite(BLUE, bval);
}
}
}
The program keeps looking for the three integer values until a newline is
detected. Once this happens, the values that were read are used to set the bright-
ness of the LEDs. To use this, open the serial monitor and enter three values
between 0 and 255 separated by a comma, like "200,30,180" . Try mixing all
kinds of pretty colors!
TalkingtoaDesktopApp
Eventually, you're bound to get bored of doing all your serial communication
through the Arduino serial monitor. Conveniently, just about any desktop pro-
gramming language you can think of has libraries that allow it to interface with
the serial ports in your computer. You can use your favorite desktop program-
ming language to write programs that send serial commands to your Arduino
and that react to serial data being transmitted from the Arduino to the computer.
In this topic, Processing is the desktop programming language of choice
because it is very similar to the Arduino language that you have already become
familiar with. In fact, the Arduino programming language is based on Processing!
Other popular desktop languages (that have well-documented serial commu-
nication libraries) include Python, PHP, Visual Basic, C, and more. First, you'll
learn how to read transmitted serial data in Processing, and then you'll learn
how you can use Processing to create a simple graphical user interface (GUI)
to send commands to your Arduino.
TalkingtoProcessing
Processing has a fairly simple programming interface, and it's similar to the
one you've already been using for the Arduino. In this section, you install
Processing, and then write a simple graphical interface to generate a graphical
 
Search WWH ::




Custom Search