Hardware Reference
In-Depth Information
background(0,0,brightness); //Updates the window
}
void serialEvent (Serial port)
{
brightness = float(port.readStringUntil('\n')); //Gets val
}
When you run the sketch, it should work just as it did when you were con-
nected directly to the Arduino with a USB cable. Run around your house or
office (if you are using a battery pack) and control the colors on your screen.
RevisitingtheSerialExamples:ControllinganRGBLED
You've now confirmed that you can send data wirelessly from your Arduino
to the computer. Next, you use the RGB LED control sketch from Chapter 6 to
confirm that you can wirelessly send commands from your computer to your
Arduino. After confirming that you can successfully send data between your
Arduino and the computer wirelessly, you can design any number of exciting
applications; you'll find some ideas listed on the webpage for this chapter.
Again, the first step is to load the appropriate program (see Listing 11-3) on
to your Arduino. Use the same program that you used in chapter six. It accepts
a string of RGB values and sets an RGB LED accordingly.
Listing 11-3: RGB LED Control via Serial— processing_control_RGB/list_control
//Sending Multiple Variables at Once
//Define LED Pins
const int RED =11;
const int GREEN =10;
const int BLUE =9;
//Variables for RGB levels
int rval = 0;
int gval = 0;
int bval = 0;
void setup()
{
Serial.begin(9600); //Serial port at 9600 baud
//Set pins as outputs
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
Search WWH ::




Custom Search