Requirements

Instructions

  1. Unzip the archive (you can donwload at http://code.google.com/p/funnel/downloads/list)
  2. Create a new project
  3. Add libraries/actionscript3/src/ to source paths
  4. Run an appropriate example in libraries/actionscript3/examples/ with Flash Player.

Reference

Gainer(config, host, portNum, samplingInterval)
Create a Gainer object. config is the configuration of Gainer such as "Gainer.MODE1" (without the quotes); host is the name or IP address of the Funnel Server (default is "localhost"); portNum is the port number of the Funnel Server (default is 9000); samplingInterval is the sampling interval in milliseconds for inputs (default is 33)
Arduino(config, host, portNum, samplingInterval)
Create an Arduino object. config is the configuration of Arduino such as "Arduino.FIRMATA" (without the quotes); host is the name or IP address of the Funnel Server (default is "localhost"); portNum is the port number of the Funnel Server (default is 9000); samplingInterval is the sampling interval in milliseconds for inputs (default is 33)
Configuration.setDigitalPinMode(number, type)
Set a digital pin to input, output or PWM mode (DIN, DOUT, AIN, or PWM).
button
Returns the Pin object of the on-board button (Gainer)
led
Returns the Pin object of the on-board LED (Gainer)
analogInput(number)
Returns the Pin object of the pin (Gainer)
analogOutput(number)
Returns the Pin object of the pin (Gainer)
digitalInput(number)
Returns the Pin object of the pin (Gainer)
digitalOutput(number)
Returns the Pin object of the pin (Gainer)
digitalPin(number)
Returns the Pin object of the digital pin (Arduino)
analogPin(number)
Returns the Pin object of the analog pin (Arduino)
Pin.value
Returns the value of the pin (from 0 to 1)
Pin.maximum
Returns the maximum value of the pin (from 0 to 1)
Pin.minimum
Returns the minimum value of the pin (from 0 to 1)
Pin.average
Returns the average value of the pin (from 0 to 1)
Pin.value =
Sets a value of a pin (from 0 to 1)
Pin.addFilter(newFilter)
Adds a new filter to the pin
Pin.setFilters(newFilters)
Sets new filters to the pin
Pin.removeAllFilters()
Removes all filters from the pin
Pin.addEventListener(event, function)
Add an event listener to the pin; event should be PinEvent.RISING_EDGE, PinEvent.FALLING_EDGE or PinEvent.CHANGE
SetPoint([threshold, hysteresis])
Create a SetPoint object; threshold is the threshold to divide an input to 1 or 1; hysteresis is the allowance for the threshold.

Examples

Gainer

package {
    import flash.display.Sprite;
    import funnel.*;

    public class GainerTest extends Sprite {
        private var gio:Gainer;

        public function GainerTest() {
            gio = new Gainer(Gainer.MODE1);

            var externalLED:Pin = gio.analogOutput(0);
            var osc:Osc = new Osc(Osc.SQUARE, 0.5);
            externalLED.addFilter(osc);

            // the on-board button is pressed
            gio.button.addEventListener(PinEvent.RISING_EDGE, function(e:Event):void {
                // turn the on-board LED on
                gio.led.value = 1;

                // start blinking
                osc.reset();
                osc.start();
            });

            // the on-board button is released
            gio.button.addEventListener(PinEvent.FALLING_EDGE, function(e:Event):void {
                // turn the on-board LED off
                gio.led.value = 0;

                // stop blinking
                osc.stop();
                osc = 0;
            });

            gio.analogInput(0).addEventListener(PinEvent.CHANGE, function(e:Event):void {
                trace("ain 0: " + e.target.value);
            }
        }
    }
}

Arduino

package {
    import flash.display.Sprite;
    import funnel.*;

    public class ArduinoTest extends Sprite {
        private var aio:Arduino;

        public function ArduinoTest() {
            var config:Configuration = Arduino.FIRMATA;
            config.setDigitalPinMode(11, PWM)// connect a LED with through a current-limiting resistor
            config.setDigitalPinMode(12, IN);   // connect a switch with a pull-down resistor
            config.setDigitalPinMode(13, OUT);

            aio = new Arduino(config);

            var button:Pin = aio.digitalPin(12);
            var onBoardLED:Pin = aio.digitalPin(13);

            var externalLED:Pin = aio.digitalPin(11);
            var osc:Osc = new Osc(Osc.SIN, 0.5);
            externalLED.addFilter(osc);

            button.addEventListener(PinEvent.RISING_EDGE, function(e:Event):void {
                // turn the on-board LED on
                onBoardLED.value = 1.0;

                // start blinking
                osc.reset();
                osc.start();
            });

            button.addEventListener(PinEvent.FALLING_EDGE, function(e:Event):void {
                // turn the on-board LED off
                onBoardLED.value = 0.0;

                // stop blinking
                osc.stop();
                osc.value = 0.0;
            });

            aio.analogPin(0).addEventListener(PinEvent.CHANGE, function(e:Event):void {
                trace("A0: " + e.target.value);
            }
        }
    }
}
package {
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    import funnel.Arduino;
    import funnel.i2c.BlinkM;

    /**
     * Arduino I2C BlinkM example
     *
     * Control a BlinkM from AS3 via Funnel
     *
     * Preparation:
     * * upload SimpleI2CFirmata to an Arduino board
     *
     * The circuit:
     * * outputs
     *   - A4: the I2C data pin
     *   - A5: the I2C clock pin
     *
     * Created 1 June 2009
     * By Shigeru Kobayashi
     *
     * http://thingm.com/products/blinkm
     * http://funnel.cc/
     * http://arduino.cc/
     * http://firmata.org/
     */

    public class ArduinoI2CBlinkM extends Sprite {
        private var pulseGenerator:Timer;
        private var aio:Arduino;
        private var blinkM:BlinkM;

        public function ArduinoI2CBlinkM() {
            aio = new Arduino(Arduino.FIRMATA);
            blinkM = new BlinkM(aio);

            pulseGenerator = new Timer(1000);
            pulseGenerator.addEventListener(TimerEvent.TIMER, onPulse);
            pulseGenerator.start();

            blinkM.stopScript();
            blinkM.goToRGBColorNow([0, 0, 0]);
        }

        private function onPulse(e:TimerEvent):void {
            blinkM.fadeToRandomRGBColor([255, 255, 255], 50);
        }
    }
}

Reference

http://funnel.cc/reference/actionscript3/


Language / 言語

Featured Pages

For Members

Not a member?