User Tools

Site Tools


courses:intro.prototyping.spring.2011.feb17

Differences

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

Link to this comparison view

courses:intro.prototyping.spring.2011.feb17 [2011/02/15 02:57]
130.239.149.1 created
courses:intro.prototyping.spring.2011.feb17 [2011/02/15 04:25] (current)
130.239.149.1
Line 1: Line 1:
 +Part of the course [[courses:​introduction_to_prototyping_spring_2011|Intro to Prototyping IxD1, Spring 2011]]
  
 +=== Phidget continued ===
 +Using what we learned last week, build a more elaborate Flash-functionality. Use Phidget sensors and gadgets to create a game, an unusually interactive webpage, a security system or anything else you fantasy can come up with.
 +
 +The following is bare minimum-example using the phidgetinterfacekit with two potentiometers as sensors.
 +<code java>
 +import com.phidgets.*;​
 +import com.phidgets.events.*;​
 +
 +var phid:​PhidgetInterfaceKit;​ //Using an interfacekit we create an interfacekitobject
 +phid = new PhidgetInterfaceKit();​ //and tell flash to listen for sensorChanges that come with the kit
 +phid.addEventListener(PhidgetDataEvent.SENSOR_CHANGE,​ onSensorChange);​
 +
 +phid.open("​localhost",​ 5001);
 +
 +//And below we specify which port on the interfacekit we care about (evt.index) and what should happen
 +// with the sensorinformation (evt.data) ​
 +function onSensorChange(evt:​PhidgetDataEvent):​void{
 + if(evt.Index == 0)
 + {
 + ship1_mc.x = (Number(evt.Data)/​2)-3;​
 + }
 + if(evt.Index == 1)
 + {
 + ship1_mc.y = (Number(evt.Data)/​2)-56;​
 + }
 +
 +}
 +</​code>​
 +
 +The following is a slimmed down example with an encoder. A knob with no end points and you can push the knob for a click-event.
 +
 +<code java>
 +import com.phidgets.*;​
 +import com.phidgets.events.*;​
 +
 +//Unlike in the previous example we create another type of object, since we're using another phidget.
 +var phid:​PhidgetEncoder = new PhidgetEncoder();​
 +//and we tell flash to lsiten to rotation and pushing
 +phid.addEventListener(PhidgetDataEvent.INPUT_CHANGE,​ onInputChange);​
 +phid.addEventListener(PhidgetDataEvent.POSITION_CHANGE,​ onPositionChange);​
 +
 +phid.open("​localhost",​ 5001);
 +
 +
 +function onInputChange(evt:​PhidgetDataEvent):​void{
 + trace(evt.Data);​
 + if(evt.Data == true)
 + {
 + fatso_mc.y = 0;
 + }
 + if(evt.Data == false)
 + {
 + fatso_mc.y = 100;
 + }
 +}
 +
 +function onPositionChange(evt:​PhidgetDataEvent):​void{
 + trace(evt.Data);​
 + fatso_mc.width = fatso_mc.width + evt.Data;
 + fatso_mc.height = fatso_mc.height + evt.Data;
 +}
 +</​code> ​
 +
 +Note that different kinds of phidgets take different types of objects and listens to differents types of events. Exactly what to write in each situation can be found in the examples found [[http://​www.phidgets.com/​downloads/​examples/​Flash_2.1.7.20110203.zip|here]] or more in detail [[http://​www.phidgets.com/​documentation/​Phidget21Flash_doc.zip|here]]. Of course I'm available to help out, as well.
courses/intro.prototyping.spring.2011.feb17.txt · Last modified: 2011/02/15 04:25 by 130.239.149.1