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

Multi_Osc_LEDs

Get Adobe Flash player
by xshige 23 Oct 2010
    Embed
/**
 * Copyright xshige ( http://wonderfl.net/user/xshige )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/d9K5
 */

//
// Multi Oscilloscope +LEDs
//
// Reference
// http://funnel.cc/Software/ActionScript3

package {
    import flash.display.Sprite;
//    import flash.events.Event;
    import flash.events.*;
    import funnel.*;
    import funnel.gui.*;
    import funnel.ui.*;

    [SWF(backgroundColor="0x808080")]
    
    public class ArduinoOSC_LED extends Sprite {
		private const NUM_CHANNELS:int = 4;
        private var aio:Arduino;
        private var scopes:Array;
		
	private var onBoardLED:LED;
	private var externalLED:LED;
	private var thirdLED:LED;
	private var squareButton1:Sprite;
	private var squareButton2:Sprite;

        public function ArduinoOSC_LED() {
	    var config:Configuration = Arduino.FIRMATA;
	    config.setDigitalPinMode(3, PWM); // connect a LED with through a current-limiting resistor
	    config.setDigitalPinMode(5, PWM);
	    config.setDigitalPinMode(6, PWM);
	    config.setDigitalPinMode(9, PWM);
	    config.setDigitalPinMode(10, PWM);
	    config.setDigitalPinMode(11, PWM); // connect a LED with through a current-limiting resistor
	    config.setDigitalPinMode(13, DOUT); // OnBoard LED
	    config.setDigitalPinMode(2, DOUT); // external LED if you have			
	    aio = new Arduino(config);

	    // button definition (button#1, button#2)
	    // button#1
	    squareButton1 = new Sprite();
            squareButton1.graphics.beginFill(0x408040);
            squareButton1.graphics.drawRect(100, -170, 50, 50);
            squareButton1.graphics.endFill();
            squareButton1.x = stage.stageWidth / 2;
            squareButton1.y = stage.stageHeight / 2;
            squareButton1.buttonMode = true;
            this.addChild(squareButton1);
            // button#2
            squareButton2 = new Sprite();
            squareButton2.graphics.beginFill(0x804040);
            squareButton2.graphics.drawRect(160, -170, 50, 50);
            squareButton2.graphics.endFill();
            squareButton2.x = stage.stageWidth / 2;
            squareButton2.y = stage.stageHeight / 2;
            squareButton2.buttonMode = true;
            this.addChild(squareButton2);
			
            // allocate LEDs
            onBoardLED = new LED(aio.digitalPin(13));
            externalLED = new LED(aio.digitalPin(2));
            // setup event for buttons
            // button#1
            squareButton1.addEventListener(MouseEvent.MOUSE_DOWN, button1Pressed);
            squareButton1.addEventListener(MouseEvent.MOUSE_UP, button1Released);
            // button#2
            squareButton2.addEventListener(MouseEvent.MOUSE_DOWN, button2Pressed);
            squareButton2.addEventListener(MouseEvent.MOUSE_UP, button2Released);
            
            thirdLED = new LED(aio.digitalPin(3));
            
//            // dump values of analog input #0
//            aio.analogPin(0).addEventListener(PinEvent.CHANGE, function(e:Event):void {
//                trace("A0: " + e.target.value);
//	    });

            scopes = new Array(NUM_CHANNELS);
            for (var i:int = 0; i < NUM_CHANNELS; i++) {
                scopes[i] = new SignalScope(5, 5 + (60 * i), 200, "A" + i);
                addChild(scopes[i]);
            };
			
            //scope = new SignalScope(0, 5, 200, "ain 0");
            //addChild(scope);

            var gui:ArduinoGUI = new ArduinoGUI();
            addChild(gui);
            aio.gui = gui;
            gui.setPosition(IOModuleGUI.RIGHT_BOTTOM);

            addEventListener(Event.ENTER_FRAME, loop);	
        }

        private function loop(event:Event):void {
            thirdLED.blink(1000, 0, Osc.SAW); // 1st param: 1000ms interval (i.e. 1Hz)
	    
            for (var i:int = 0; i < NUM_CHANNELS; i++) {            
                scopes[i].update(aio.analogPin(i));
            };
         }
				

        private function button1Pressed(e:MouseEvent):void {
	    // you can choose one of the folloiwng three // 
            onBoardLED.on();
	    //onBoardLED.value = 1;
	    onBoardLED.blink(100, 0, Osc.SQUARE);
            squareButton1.scaleX = 1.02;
            squareButton1.scaleY = 1.02;
        }

        private function button1Released(e:MouseEvent):void {
	    // you can choose one of the folloiwng three // 
            onBoardLED.off();
	    //onBoardLED.value = 0;
	    onBoardLED.stopBlinking();
            squareButton1.scaleX = 1.0;
            squareButton1.scaleY = 1.0;
        }

	private function button2Pressed(e:MouseEvent):void {
	    // you can choose one of the folloiwng two // 
            externalLED.on();
	    //externalLED.blink(500, 0, Osc.SQUARE);
            squareButton2.scaleX = 1.02;
            squareButton2.scaleY = 1.02;
        }

        private function button2Released(e:MouseEvent):void {
	    // you can choose one of the folloiwng two // 
            externalLED.off();
	    externalLED.stopBlinking();
            squareButton2.scaleX = 1.0;
            squareButton2.scaleY = 1.0;
        }

    }
}