Hardware Reference
In-Depth Information
Figure 3-5. Arduino circuit for the “Expanding on the Idea” example
For the rest of this example, the only changes are going to be to the code.
For the hardware, the potentiometer is going to control the servo, while the brightness of the LED on pin 3 will
represent the position of the servo. When the button is pressed, the LED on pin 13 will turn on; at the same time, the
servo and the other LED will pause and stop accepting new values from the potentiometer until the button is released.
Changing Code
While openFrameworks is controlling the Arduino, it will simultaneously be displaying a representation of what the
hardware is doing. The program will have a window the same size as the two prior examples, with shapes representing
the button, the LED, and the potentiometer's position. The only change to the graphics is that we will dynamically
change the color of the bar to represent the new brightness value for the LED, with the color fading from black to full
red with the servo and potentiometer's full swing.
Open the project from Listings 3-5 and 3-6. The same main.cpp will be used without alteration. Within
testapp.cpp , the entire mousePressed() function can be removed or commented out, along with its prototype in
testapp.h . You can omit the following line from the arduinoLoop() function:
arduino.sendDigital(13, ledcommand);
The last thing to comment out is the variable declaration bool ledcommand; from testapp.h . With the code that
is no longer needed out of the way, change the line ofSetColor(255,0,0); , located in the draw() function, to
ofSetColor((analogPin0*255),0,0);
 
Search WWH ::




Custom Search