Why Flash? (and not processing)
A Short intro into why we are using Flash
- Setting up Arduino (Yes, AGAIN!)
- What is Arduino?
Setting up your Arduino (Yes. Again.)
- Load the 'Standard Firmata' Example.
- Verify the Code.
- Upload Code.
- Opps.. If you see this.
You need to select Tool > Board > Arduino Duemilanove . ATMEGA328
- Download AS3Glue. - Unzip to Documents.
- Locate Serproxy-0.1.3-3. Located in Glue > Applications > Serproxy-0.1.3-3 .
- If in Windows delete serproxy.cfg & serproxy.cfg.mac
- If you are using a COMM port above 10. Use this software.
- Open serproxy.cfg.win, edit with below and save with name serproxy.cfg
# Example configuration file for serproxy - PC Version # For use with Firmata 2.0 # Note: in this example, Arduino uses COM3 - this is reflected in the line comm_ports=3 and net_port3=5331 below. # If your board is on COM4, you'd have to change those lines to comm_ports=4 and net_port4=5331. # Do not Transform newlines coming from the serial port into nils newlines_to_nils=false # Comm ports used comm_ports=5 # Default settings comm_baud=115200 comm_databits=8 comm_stopbits=1 comm_parity=none # Idle time out in seconds timeout=300 # Settings for COM5 net_port5=5331
!! IMPORTANT !! To get this to work, you need net_port5= to match your Comm Port. - e.g. comm_port=2 -- net_port2=
- e.g. comm_port=3 -- net_port3=
- e.g. comm_port=6 -- net_port6=
- Run Serproxy
- Copy AS3Libary [ Glue > as3 > net ] into example > arduino > blink.
- Insert an LED into pin 13.
- Run the application.
Did it work?
Ask me. To Help.
Some Code Snippets to get you thinking. Edited from bjoern
Using a Mouse to control an LED.
var ledState:int = Arduino.HIGH;
function onMouseClickEvent(event:MouseEvent):void {
if(ledState==Arduino.HIGH) {
ledState=Arduino.LOW;
}else {
ledState=Arduino.HIGH;
}
arduino.writeDigitalPin(ledPin, ledState);
}
stage.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
Doing that Apple Flashign LED PWN thing.
var ledPin:Number = 9;
var arduino:Arduino = new Arduino("127.0.0.1", 5113);
var pwmValue:Number=0;
var rising:Boolean=true;
var step:Number=10;
// we first ask for the Firmware version, when it comes back, we know it's safe to initialize
arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onArduinoStartup);
arduino.requestFirmwareVersion();
// Arduino initialization
function onArduinoStartup(e:ArduinoEvent):void {
arduino.setPinMode(ledPin, Arduino.PWM);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
trace("Arduino initialized.");
}
function onEnterFrame(event:Event):void {
if(rising) {
pwmValue+=step;
if(pwmValue>=254) {
rising=false;
pwmValue=254;
}
} else {
pwmValue-=step;
if(pwmValue<=0) {
rising=true;
pwmValue=0;
}
}
// show current pwmValue value in window
label.text=pwmValue.toString();
// write pwm value to Arduino
arduino.writeAnalogPin(ledPin,pwmValue);
}
Swith Input
import net.eriksjodin.arduino.Arduino;
import net.eriksjodin.arduino.events.ArduinoEvent;
var inputPin:Number = 2;
var arduino:Arduino = new Arduino("127.0.0.1", 5331);
// we first ask for the Firmware version, when it comes back, we know it's safe to initialize
arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onArduinoStartup);
arduino.requestFirmwareVersion();
// Arduino initialization
function onArduinoStartup(e:ArduinoEvent):void {
arduino.setPinMode(inputPin, Arduino.INPUT);
arduino.enableDigitalPinReporting();
trace("Arduino initialized.");
}
function onReceiveDigitalData(e:ArduinoEvent):void {
//trace(e);
if(e.pin==inputPin) {
if (e.value==Arduino.HIGH) {
[NameOfMovieClip]visible=false;
} else {
[NameOfMovieClip].visible=true;
}
}
}
//PLACE A MOVIECLIP ON THE SCREEN
[NameOfMovieClip].visible=false;
arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
Example of Haptics
// vibra_control_01
// turn vibration motor connected to pin2 on Arduino on when mouse is pressed,
// off when mouse is released
// bjoern@stanford.edu 2/12/08, REVISED 12/15/08
import net.eriksjodin.arduino.Arduino;
import net.eriksjodin.arduino.events.ArduinoEvent;
import flash.events.MouseEvent;
var pin:Number = 2;
var arduino:Arduino = new Arduino("127.0.0.1", 11100);
// we first ask for the Firmware version, when it comes back, we know it's safe to initialize
arduino.addEventListener(ArduinoEvent.FIRMWARE_VERSION, onArduinoStartup);
arduino.requestFirmwareVersion();
// Arduino initialization
function onArduinoStartup(e:ArduinoEvent):void {
arduino.setPinMode(pin, Arduino.OUTPUT);
arduino.writeDigitalPin(pin, Arduino.LOW);
trace("Arduino initialized.");
}
function onMouseClickEvent(event:MouseEvent):void {
if(event.buttonDown) {
arduino.writeDigitalPin(pin, Arduino.HIGH);
}else {
arduino.writeDigitalPin(pin, Arduino.LOW);
}
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseClickEvent);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseClickEvent);
Next stop.. The Alcohol Sensor.