Hardware Reference
In-Depth Information
SendSerialMessage = false; // reset the need to send data to the Arduino
}//end testApp::update
void testApp::draw(){ // defines placement and draws objects in the window
ofFill(); // fills geometry with a solid color
if (Returned == 'h') // is the button on the Arduino being pressed
ofSetColor(0,0,255); // set the first circle color to full blue
else // the button is not pressed or the state is not known
ofSetColor(0,0,127); // set the first circle color to 1/2 blue
ofCircle(50,50, 50); // draw the first circle at last set color
if (ledcommand == 'a') // should the LED be on
ofSetColor(0,255,0); // set color to full green for the second circle
else // LED should be off or not known
ofSetColor(0,127,0); // set color to 1/2 green for the second circle
ofCircle(150,50, 50); // draw the second circle at last set color
} //end void testApp::draw()
void testApp::mousePressed(int x, int y, int button){
SendSerialMessage = true; // inform update function that there is data to send
if(ledcommand == 'a') // if the LED is ON
ledcommand = 's'; // change LED to be OFF
else // if the LED is OFF
ledcommand = 'a'; // change LED to be ON
} //end testApp::mousePressed
Verifying the Code
Make sure that the Arduino that was set up in Listing 3-1 is plugged into the computer and take note of the port that it
is plugged into.
COM* is for Windows
/dev/tty* is used for Linux/Unix and Mac OS X
Change the serial.setup(COM4,9600) line in Listing 3-4 to match the Arduino's connecting point. Once the test
app is set to know where the Arduino is, compile the examples. Running the program will open a window frame that
looks like Figure 3-2 , with the first circle representing the push button and the second circle showing the state of the
LED. To change the LED state, click in the window with the mouse.
Figure 3-2. Example of the running program
 
Search WWH ::




Custom Search