What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated Feb 26, 2008 by erik.sjodin
Reference  
Quickstart reference

Contributed by Bjoern Hartmann, originally written for protolab

Creation

Create an arduino object with the following line:

arduino = new Arduino("127.0.0.1", 5331);

"127.0.0.1" is the IP address where serialproxy is running - in this case, localhost. 5331 is the port number that the serialproxy TCP socket server uses as defined in serproxy.cfg.

Digital I/O

arduino.setPinMode(pin, Arduino.INPUT); arduino.setPinMode(pin, Arduino.OUTPUT);
where pin is a Number variable with value between 2 and 13.
arduino.writeDigitalPin(pin, Arduino.HIGH); arduino.writeDigitalPin(pin, Arduino.LOW);
arduino.enableDigitalPinReporting(); arduino.disableDigitalPinReporting();
arduino.getDigitalData(pin);

Analog I/O

arduino.setPinMode(pin, Arduino.PWM);
arduino.writeAnalogPin(pin, value);
where value is a Number variable between 0 and 255.
arduino.setAnalogPinReporting(aPin, Arduino.ON); arduino.setAnalogPinReporting(aPin, Arduino.OFF);
where aPin is a Number variable with value between 0 and 6.
arduino.getAnalogData(aPin);

Event listener functions

Instead of reading values through getAnalogData() and getDigitalData(), as3glue can also use event listener functions you supply whenever a digital or analog pin changes. You have to do two things: write a callback function and register that function with the object. Here are examples:

public function onReceiveDigitalData(e:ArduinoEvent):void {
trace("Digital pin " + e.pin + " on port: " + e.port +" = " + e.value);
}
Then register it with the arduino object:
arduino.addEventListener(ArduinoEvent.DIGITAL_DATA, onReceiveDigitalData);
public function onReceiveAnalogData(e:ArduinoEvent):void {
trace("Analog pin " + e.pin + " on port: " + e.port +" = " + e.value);
}
Then register it with the arduino object:
arduino.addEventListener(ArduinoEvent.ANALOG_DATA, onReceiveAnalogData);

Sign in to add a comment