Hardware Reference
In-Depth Information
pinMode(BLUE, OUTPUT);
}
void loop()
{
//Keep working as long as data is in the buffer
while (Serial.available() > 0)
{
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);
}
}
}
Next, wire up the Arduino just as you did in Chapter 6 (with the addition of
the wireless shield and XBee radio), as shown in Figure 11-18.
As in the previous section, connect your USB Explorer to your computer and
launch the Processing sketch, which is shown in Listing 11-4. Make sure you
put the hsv.jpg file into the data folder of the sketch, as you did in Chapter 6 (It
is included in the online code download). Before running the sketch, be sure
to set the serial port name to the correct value.
Listing 11-4: Processing Sketch to Set Arduino RGB Colors —processing_control_RGB/
processing_control_RGB
import processing.serial.*; //Import serial library
PImage img; //Image object
Serial port; //Serial port object
void setup()
{
size(640,256); //Size of HSV image
img = loadImage(“hsv.jpg”); //Load in background image
port = new Serial(this, “COM9”, 9600); //Open serial port
}
void draw()
{
background(0); //Black background
image(img,0,0); //Overlay image
}
Search WWH ::




Custom Search