User Tools

Site Tools


courses:intro.prototyping.spring.2011.mar03

Part of the course Intro to Prototyping IxD1, Spring 2011

Phidget final

Tying together the Phidget experience with looking at how to use several phidgets of the same type, and controlling a servo.

Using several phidgets is more or less the same as creating several variables. You do the same as with one, but several times and call them different things. In this case, phidget encoders:

//Using two Phidget encoders, we need to declare them as two separate things
var encoder1:PhidgetEncoder; 
encoder1 = new PhidgetEncoder();
 
var encoder2:PhidgetEncoder;
encoder2 = new PhidgetEncoder();

What's different is also that to keep track of which physical phidget corresponds to which in the code we connect it to the web service using the ID# found in the phidget control panel. So instead of:

encoder.open("localhost", 5001);

we write

encoder1.open("localhost", 5001, "", XXX);
encoder2.open("localhost", 5001, "", XXX);

where XXX is the ID#.

After that it's just a question of doing what you've done before. Tell Flash what to listen for, what functions to run when it notices a change and what those functions should do.

//and we tell flash to listen to rotation and pushing for each encoder.
encoder1.addEventListener(PhidgetDataEvent.INPUT_CHANGE, onInputChange);
encoder1.addEventListener(PhidgetDataEvent.POSITION_CHANGE, moveYwise);
 
encoder2.addEventListener(PhidgetDataEvent.INPUT_CHANGE, onInputChange);
encoder2.addEventListener(PhidgetDataEvent.POSITION_CHANGE, moveXwise);
 
function onInputChange(evt:PhidgetDataEvent):void{
   //stuff happens when button is pressed
 
}
 
function moveYwise(evt:PhidgetDataEvent):void{
   //stuff happens when one knob is turned
}
 
function moveXwise(evt:PhidgetDataEvent):void{
  //stuff happens when the other knob is turned
}   

Done? Too simple? Good, take a look at the examples from the Phidget website for motor control and servos and see if you can incorporate some moving action from flash.

courses/intro.prototyping.spring.2011.mar03.txt · Last modified: 2011/03/02 07:36 by 130.239.149.78