Topic: Light Sensor
Having trouble getting numbers out of the light sensor. Anyone had any sucess with this?
You are not logged in. Please login or register.
chumbysphere forum → Flash/Widget → Light Sensor
Having trouble getting numbers out of the light sensor. Anyone had any sucess with this?
Unfortunately, the light sensor is pretty nonlinear, so the range of output values isn't very large and is somewhat noisy.
If you're not getting *anything*, please post the Actionscript you're using so we can take a look at it and diagnose the problem.
On the stage is a text field with a variable name of "_light"
this.onEnterFrame = function () {
_light.text = ASnative(5,15);
}
It displays the data type and not the data?
ASNative() returns the function pointer - you need to then call the function to get the value
_lightSensor = ASNative(5,15);
trace(lightSensor());
sweet, it worked:
_light = ASnative(5,15);
//
this.onEnterFrame = function () {
lightMeter.text = _light();
}
The numbers coming out of the thing are a bit noisy, but really not that bad esp. compared to audio analysis.
I'm getting a range of ~20 for the low end (when the sensor is completely covered with a finger and put in a dark corner somewhere) and ~2490 (when the sensor is put a half inch away from a 20 watt bulb).
A "doped" value can be prepared from the raw data, using techniques from audio analysis.
Noticed that when light is almost non-existant the reading rapidly flickers between ~20 and ~40, with no in-between. A threshold script that ignores readings below 50 would fix that. Essentially making the raw value of 50 become the doped value of 0.
As far as the noise goes in the rest of the signal (which for my purposes is great, way better than Math.random()) it could be evened out by comparing current to past values and only changing the doped value when the raw value changes by a certain amount. The noise seems to range from +/- 20 so a script that only changed the doped value when the raw value changes by 20 or more would even it out quite a bit.
ok, script based on my previous comments. A bit crude but it works. On the stage place dynamic textfields with the names mentioned in the script to view the values on the chumby.
_lightPointer = ASnative(5,15);
this.onEnterFrame = function () {
/*
** save previous value for signal smoothing
*/
_oldLight = _lightRaw;
/*
** get current value
*/
_lightRaw = _lightPointer();
lightRaw.text = _lightRaw;
/*
** signal lower threshold
*/
if (_lightRaw <= 50) {
_lightRaw = 0;
}
/*
** turn into a percentage
*/
_lightPercent = _lightRaw/2500;
lightPercent.text = _lightPercent;
/*
** signal smoothing
*/
if ((_lightRaw <= _oldLight-20) || (_lightRaw >= _oldLight+20)) {
_lightSmooth = _lightRaw+((_lightRaw-_oldLight)/2);
//
if (_lightSmooth <= 0) {
_lightSmooth = 0;
}
//
lightSmooth.text = _lightSmooth;
//
_lightSmoothPercent = _lightSmooth/2500;
lightSmoothPercent.text = _lightSmoothPercent;
}
//
}
how do i turn on the light sensor?
how do i turn on the light sensor?
The light sensor was only available in the alpha prototypes, and was removed from the production device - it was a bit too flaky.
It was replaced by the microphone, which is intended to be supported in the future.
chumbysphere forum → Flash/Widget → Light Sensor
Powered by PunBB, supported by Informer Technologies, Inc.