Software

Running the projBox Tester Application

The projBox Tester application draws a graphical representation of the projBox’s knobs and switches. The app is designed to test a newly assembled projBox to see if everything is connected correctly.

The graphical image of the projBox components change along with the ones on the physical projBox connected to the computer, i.e. if you turn a knob on the box it will rotate the corresponding knob in the Tester application.

Download the projBoxTester sketch.

For the application to work you must first load Standard Firmata onto the Arduino board that is in the projBox. Follow the last steps at the bottom of the Assembly page to see how to do this.

Open the file “projBoxTester.pde” in the Processing native IDE and press play to compile and run it.

The ProjBox Class

The following software class for Processing is designed to provide a simple API for interfacing with the projBox hardware. The class provides a software abstraction of the projBox hardware and utilizes the Firmata libraries.

This class is provided as a “tab” in the projBoxTester source code. The projBoxTester code demonstrates a simple example of how to implement the class. Add the file projBox.pde to any Processing sketch that you’d like to integrate with the projBox hardware controller.


Using the ProjBox Class

The following shows how to implement the class in a Processing sketch and the available methods and properties of the ProjBox class.


ProjBox projBox;

Declares a projBox object instance. This line should be at the top of the code above setup().


projBox = new ProjBox();

Instantiates the declared projBox instance. This line should be inside the setup() function.

When the function first runs it will look for the first item in your serial device chain and attempt to access it. The function also prints a list of available serial devices. If your Arduino is not the first item in that list pass the name of your Arduino serial device when instantiating the ProjBox() object:

projBox = new ProjBox(“your arduino serial name”);


projBox.getData();

Gets the current potentiometer and switch positions from the projBox hardware. This is typically called at the beginning of the draw() function so that the latest data is available to the rest of the code every loop iteration.


projBox.knobs[n]

Returns the position of a potentiometer as an integer with a range of 0 to 1023, where n is the number of the potentiometer being polled. [0] is the first potentiometer on the left and [3] is the rightmost potentiometer.


projBox.switches[n]

Returns the position of a switch as an integer with the value of 0 (off) or 1 (on), where n is the number of the switch being polled. [0] is the first switch on the left and [3] is the rightmost switch.


projBox.switchMatrix

Returns a string representing the on/off states of all switches as “0″s and “1″s.

Use this in an if() statement to run code only when certain combinations of switches are flipped. Use the String.equals() function to compare this value to a preset string representation of the switches.

For example, to run a function called yourFunction() when only the left and right switches are on you could write:

if(projBox.switchMatrix.equals(“1001″)) yourFunction();


ledDisplaySwitches(n)

Uses the LEDs on the projBox hardware to display the switch states. This is used inside the getData() function of the ProjBox class itself. n is the row of the LED/switch match.


ledDisplayKnobs(n)

Uses the LEDs on the projBox hardware to display the potentiometer positions. Replace the ledDisplaySwitches() with this function inside getData() in the ProjBox class itself to have the LEDs change brightness with the potentiometer position. n is the row of the LED/potentiometer match.






Photo by Matt Westervelt