Products for USB Sensing and Control
Products for USB Sensing and Control

Processing and Phidgets - Windows

Learn how to add Phidgets to your Processing applications.


by Phidgets Education

Introduction

Now that you've completed the Getting Started kit and have a basic understanding of programming with Phidgets, you can easily integrate sensors into your Processing projects.

Prerequisites

This project assumes you have an understanding of Processing and have completed the Getting Started Kit.

For more information, check out the Student Page.


Hardware

You will need:

  • A Getting Started Kit

Setup:

Connect your Getting Started Kit to your computer.


Add the Phidget Library


Get started by opening Processing and saving a new sketch as Phidgets_Processing_Test


Next, navigate to C:/Program Files/Phidgets/Phidget22 and find phidget22.jar


Drag phidget22.jar onto your sketch and release:


Verify that Phidget libraries were added to your sketch by navigating to the location of your sketch. There will be a new folder called code:

Inside the code folder there will be a copy of phidget22.jar:


The last step is to reference the Phidget library by adding the following line of code to your sketch:



Write Code

Now that you've added the Phidget Libraries to your Processing project, you can start coding.


Start by adding a setup() method that creates a window and an empty draw() method.


Next, define a DigitalInput object, and then create and address it in your setup() method. Don't forget about error handling!

  1. Define a boolean called buttonPresed.
  2. Add a state change listener for your DigitalInput object before the open call.
  3. Check if the button's been pressed, and update the buttonPressed variable.


Next, modify your draw() method to check the state of the boolean variable. Modify your window's background color based on the state.


Always be sure to override the exit() method to close your Phidgets properly!


Run your code. Your window's background should change from black to green when the button is pressed.


Conclusion

Now that you know how to use Phidgets with Processing, try creating your own project with the Phidgets in your classroom. If you need inspiration, check out the links below: