AnalogInput

This widget connects to the analog inputs of a microcontroller and provides some processing of the sensor values as they come in. The default range for analog inputs for the Make Controller and Brainstem is 0 - 1023, but this range can be scaled by AnalogInput to any range desired by setting the min and max numbers. AnalogInput also has a fader knob which allows the user to simulate the values of a sensor coming in, so the user can test other parts of their application with no external hardware hooked up.

On Screen Features

Parameters

netFeed(feedValue, feedID) Explanation

If you need to access the values generated by the ../AnalogInput (and ../DigitalInput) widgets in ActionScript, the widgets always call the function netFeed(feedValue, feedID) for themselves. So by creating a netFeed() function attached to the ../AnalogInput widget, you can create custom code to process the values.

The parameters for the netFeed(feedValue, feedID) function are:

The following code example shows how two ../AnalogInput widgets (called analog1 and analog 2) can control the rotation of a movieClip (called rectangle). This code should be put on the first frame of the timeline, and is written in the more modern coding style that avoids putting code on movieClips directly.

Here is an example Flash file with this code: netFeedExample.fla.zip

// initialize the variables that keep the last values of each AnalogInput widget
lastAnalog1 = 0;
lastAnalog2 = 0;

// create a netFeed function on the AnalogInput instance named analog1
analog1.netFeed = processNetFeed;

// create a netFeed function on the AnalogInput instance named analog2
analog2.netFeed = processNetFeed;

// function to handle the values coming in from the AnalogInput widgets
function processNetFeed(feedValue, feedID) {
        if (feedID == "analog1") {
                _root.lastAnalog1 = feedValue;  
        } else if (feedID == "analog2") {
                _root.lastAnalog2 = feedValue;  
        }
}

// create an onEnterFrame function for the rectangle to animate it
rectangle.onEnterFrame = function() {
        // compare the saved values from the analogInput widgets
        if (_root.lastAnalog1 > _root.lastAnalog2) {
                // rotate right
                this._rotation += 8;
        } else if (_root.lastAnalog1 < _root.lastAnalog2) {
                // rotate left
                this._rotation -= 8;
        }
}

setSensorValue(sensorValue) Explanation

Sometimes you need to be able to control the external world (lights, servos, etc.) through code. The ../AnalogInput (and ../DigitalInput) widget provides a mechanism for this, by allowing code to control its values as if it were an external sensor. The ../AnalogInput widget will listen to code through its setSensorValue() function if you set the "controller" parameter of the component in the Properties Inspector to "code". Since all the output widgets can listen to an ../AnalogInput or ../DigitalInput widget, your code can control any output by changing the values of these input widgets.

The parameter for the setSensorValue(sensorValue) function is:

The following code example shows how simple code can turn a light on or off. In this example, an ../AnalogInput widget (instance name codeAnalog) is controlled by code attached to a movieClip on the stage. Pressing this movieClip (instance name lightButton) sets the sensor value of the widget to 750 and releasing the button sets the value to 0. A ../DigitalOutput widget uses the AnalogInout widget as the source of values to determine if a light (or other device) attached to port 0 should turn on or off.

Here is an example Flash file with this code: controlOutput.fla.zip

// set up functions for movieClip

lightButton.onPress = function () {
        // set the value of the AnalogInput widget
        _root.codeAnalog.setSensorValue(750);
}

lightButton.onRelease = function() {
        // set the value of the AnalogInput widget
        _root.codeAnalog.setSensorValue(0);
}

Documentation/Interface/AnalogInput (last edited 2007-10-13 05:36:02 by PhilipVanAllen)