Arduino & ActionScript
Arduino & ActionScript
GeorgeProfenza
Who am I (today) ?
I am George Profenza
I do R&D at disturb media http://disturbmedia.com
I graduated from the Creative Computing course at Goldsmiths, University of London, where we had the Physical Computing course with the awesome Daniel Hirschmann
http://creativecomputation.co.uk http://www.danielhirschmann.com
credits: http://www.kalipedia.com
What is Arduino ?
"Arduino is an open-source electronics prototyping platform based on exible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments." arduino.cc
What is Arduino ?
"Arduino is an open-source electronics prototyping platform based on exible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments." arduino.cc
What is Arduino ?
digital pins
What is Arduino ?
What is Arduino ?
The Arduino IDE
Mini Weather Station Arduino Synthesiser How are you ? Light driven robot Project Monster - Big Eye More cool stuff in the Resources slides
Hello World
void setup(){//runs once pinMode(11,OUTPUT);//set pin 11 as output } void loop(){//runs over and over again, like ENTER_FRAME digitalWrite(11,HIGH);//turn pin 11 ON delay(500);//wait digitalWrite(11,LOW);//turn pin 11 OFF delay(500);//wait }
http://arduino.cc/en/Tutorial/Blink
Hello World
void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(0); Serial.println(sensorValue, DEC); }
PWMLED
int ledPin = 9; void setup() { Serial.begin(9600); pinMode(ledPin,INPUT); } void loop() { int sensorValue = analogRead(0); Serial.println(sensorValue, DEC); analogWrite(ledPin,int(sensorValue * 0.25)); }
IR Range
//for details see: http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html //k constant works for Sharp 2Y0A02 range sensor 20-150 cm oat k = 1.02f; oat value = 0.0f; void setup(){ Serial.begin(9600); } void loop(){ value = (1/(oat(analogRead(0))/1024.0f) + k) * 10; Serial.println(value); }
Flash Blink
/* Orginial code by Mike Chambers see details here: http://www.mikechambers.com/ blog/2010/08/04/gettingstarted-with-ash-and-arduino/ */ #dene LED_PIN 13 #dene TOGGLE_LED_STATE 't' #dene EOL_DELIMITER "\n" int incoming = 0; int wait = 500; boolean shouldBlinkLED = false; void setup() { Serial.begin(9600); Serial.print("INITIALIZING"); Serial.print(EOL_DELIMITER); pinMode(LED_PIN, OUTPUT); blinkLED(5); Serial.print("READY"); Serial.print(EOL_DELIMITER); }
Flash Blink
void loop() { if(shouldBlinkLED) blinkLED(1); if(Serial.available() > 0){ incoming = Serial.read(); if(incoming == TOGGLE_LED_STATE){ shouldBlinkLED = !shouldBlinkLED; Serial.print("LED BLINK STATE: "); if(shouldBlinkLED) Serial.print("ON"); else Serial.print("OFF"); Serial.print(EOL_DELIMITER); } } } void blinkLED(int count){ for(int i = 0; i < count; i++){ digitalWrite(LED_PIN, HIGH); delay(wait); digitalWrite(LED_PIN, LOW); delay(wait); } }
Interfacing
Interfacing with Actionscript Using serproxy Arduino setup - sends messages through serial serproxy setup - make sure baud rate and board match(cfg) open up serproxy.cfg in a text edit set the serial_device to your device port (Tools>Serial Ports) set the baud rate Flash setup - open a binary socket and read/write values
Interfacing
Firmata "Firmata a generic protocol for communicating with microcontrollers like the Arduino from software on a host computer. " arduino.cc
Interfacing
Alternatively for as3 use as3glue, uses Firmata tutorial here: http://blog.jvers.com/?tag=ash-as3glue-arduino-rmata-pcomp
Recap
Arduino: digital pins setup input
- pinMode(pinNo, INPUT); output - pinMode(pinNo, OUTPUT); reading values (0 - 1024) analog - analogRead(analogPinNo); digital - digitalRead(digitalPinNo); writing values (0 - 256) analog - analogWrite(pin,value); digital - digitalWrite(pin,value); serial Serial.begin(baudRate); Serial.print();Serial.println(); PWM is NOT affected by delay() - internal timer
Recap
Arduino.cc (tutorials/forums) Plankman wiki / Physical Computing list components: UK: cool components,rapidonline etc US,Germany,etc: adafruit,sparkfun electronics other Arduino compatible boards Freeduino Seeduino other Boards Phidget fun projects hack-a-day