User Tools

Site Tools


courses:intro.prototyping.spring.2012.apr02

Phidgets

Phidgets are a set of “plug and play” building blocks for “low cost” USB sensing and control from your PC.

All the USB complexity is taken care of by libraries. Applications can be developed quickly by programmers using their favorite language: C/C++, C#, Cocoa, Delphi, Flash AS3, Flex AS3, Java, LabVIEW, MATLAB, Max/MSP, MRS, Python, REALBasic, Visual Basic.NET, Visual Basic 6.0, Visual Basic for Applications, Visual Basic Script, and Visual C/C++/Borland.NET.

We will look into how this can be used in Flash and AS3.

Webservice

To convey the input from the Phidget hardware to your Flash-project you need to install drivers and run a webservice. Download your flavor from here.

Libraries and examples

The library files and a buttload of examples are in thisZip-file. Get that too.

Weird class

The class did not end up like I expected. More of you were interested in flash than I expected and got it working, we also ran into some weird errors, and also some people got working on phidgets in processing. But anyway, here are the example code I did.

//importing the phidget libraries
import com.phidgets.*;
import com.phidgets.events.*;
 
//creating an RFID-phidget object
var rfid:PhidgetRFID = new PhidgetRFID();
 
//having the that object pay attention to these events with the corresponding functions
rfid.addEventListener(PhidgetDataEvent.TAG, onTag);
rfid.addEventListener(PhidgetDataEvent.TAG_LOST, onTagLoss);
 
//connecting the object with the real thing
rfid.open("localhost", 5001);
 
//done when a tag is read
function onTag(evt:PhidgetDataEvent):void{
	trace(evt);
	if(evt.Data == "01023c21aa")
	{
		ghoul1.alpha = 100;
	}
 
 
	if(evt.Data == "01023c09b0")
	{
		child1.alpha = 100;
	}
 
	if(evt.Data == "01023c0cc4")
	{
		hag1.alpha = 100;
	}
}
 
//done when a tag is removed
function onTagLoss(evt:PhidgetDataEvent):void{
	trace(evt);
	hag1.alpha = 0;
	child1.alpha = 0;
	ghoul1.alpha = 0;
	rfid.LED = false;
}
Audio bits
//preparing a sound variable "childsound", the soundfile in the same folder as the project
var childSound:Sound = new Sound(new URLRequest("CHILD-CRY8.mp3"));
 
//if your sound is not just a short effect and might need to be stopped
//you need to create a soundchannel
var my_channel:SoundChannel = new SoundChannel();
 
//playing the sound
childSound.play();
 
//stopping the sound with the soundchannel
my_channel.stop();

From Flash CS5.5 there is also a tool called Code snippets. If you mark an object on the stage you can get prepared code bits for many different fun behaviours. Rotation, fade in/out etc.

courses/intro.prototyping.spring.2012.apr02.txt · Last modified: 2012/04/02 08:09 by 130.239.235.163