In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2011-10-5

Get Adobe Flash player
by y.goodspeed 05 Oct 2011
    Embed
/**
 * Copyright y.goodspeed ( http://wonderfl.net/user/y.goodspeed )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/db4T
 */

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.*;
    import funnel.*;
    import funnel.gui.*;
    import funnel.ui.*;
    
    public class ServoControl extends Sprite {
        
        private var arduino:Arduino;
        private var servo:Servo;
        
        public function ServoControl() {
            
            // setting servo to arduino
            var config:Configuration = Arduino.FIRMATA;
            config.setDigitalPinMode(9, SERVO);
            config.setDigitalPinMode(8, IN);
            arduino = new Arduino(config);

            // create servo object
            servo = new Servo(arduino.digitalPin(9));
            
            var obj1:TextField = new TextField();
            obj1.text = "release";
            obj1.y = 100;
            addChild(obj1);

            var obj2:TextField = new TextField();
            obj2.text = "lock";
            addChild(obj2);
            
            var gui:ArduinoGUI = new ArduinoGUI();
            addChild(gui);
            arduino.gui = gui;
            
            obj1.addEventListener(MouseEvent.MOUSE_DOWN, function(e:Event):void {
                release();
            });
            
            obj2.addEventListener(MouseEvent.MOUSE_DOWN, function(e:Event):void {
                lock();
            });

            var button:Button = new Button(arduino.digitalPin(8));
            button.addEventListener(ButtonEvent.PRESS, function(e:Event):void {
                lock();
            });
        }
        
        public function release():void{
            servo.angle = 90;
        }
        public function lock():void{
            servo.angle = 180;
        }
    }
}