User Tools

Site Tools


courses:intro.prototyping.spring.2011.mar03

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:intro.prototyping.spring.2011.mar03 [2011/03/02 07:33]
130.239.149.78
courses:intro.prototyping.spring.2011.mar03 [2011/03/02 07:36] (current)
130.239.149.78
Line 1: Line 1:
 +Part of the course [[courses:​introduction_to_prototyping_spring_2011|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:
 +<code java>
 +//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();​
 +</​code>​
 +
 +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:
 +<code java>
 +encoder.open("​localhost",​ 5001);
 +</​code>​
 +we write
 +<code java>
 +encoder1.open("​localhost",​ 5001, "",​ XXX);
 +encoder2.open("​localhost",​ 5001, "",​ XXX);
 +</​code>​
 +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.
 +
 +<code java>
 +//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
 +}   
 +</​code>​
 +
 +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