Upload
orgicus
View
129
Download
2
Embed Size (px)
Citation preview
George Profenza
Arduino & ActionScript
Who am I (today) ?
I am George Profenza I do R&D at disturb mediahttp://disturbmedia.com
I graduated from the Creative Computing course atGoldsmiths, University of London,where we had the Physical Computing course withthe awesome Daniel Hirschmann
http://creativecomputation.co.ukhttp://www.danielhirschmann.com
What is Physical Computing ?
Marrying the analog world with the digital world
What is Physical Computing ?
Marrying the analog world with the digital world
It happens all around us. We’re surrounded by sensors and actuators
Sensors:LightTemperatureDistanceRotationPressureKnock
Actuators/motors:ServoDCStepper
credits: winjohn, sxc.hu (http://www.sxc.hu/photo/645188) credits: http://www.kalipedia.com
What is Physical Computing ?
Marrying the analog world with the digital world
credits: University of Portsmouth,Department of Electronic and Computer Engineering
credits: Interactive Environments Lab (http://medialappi.net/lab/)
What is Arduino ?
"Arduino is an open-source electronics prototyping platform based on flexible, 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 flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments."
arduino.cc
Arduino = Hardware + Software
What is Arduino ?
digital pins
analog pins
power
serial toUSB
power selectjumper
DC in
What is Arduino ?
Bruce by Tom Juddhttp://vimeo.com/5138697
1. Type code in the IDE2. Upload it on the board through USB
What is Arduino ?
The Arduino IDE
• built on Processing• code editor, tools + terminal included• syntax is simplified C
Most of the code you’ll need in one slide:
• pinMode();• digitalRead() / digitalWrite()• analogRead() / analogWrite()• delay() / millis()• Serial.begin() / Serial.print()
What can you do with it ?
http://learn.plankman.com/w/index.php?title=Goldsmiths,_Autumn_2009 Mini Weather Station Arduino SynthesiserHow are you ? Light driven robotProject 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
float k = 1.02f;float value = 0.0f;void setup(){ Serial.begin(9600);}void loop(){ value = (1/(float(analogRead(0))/1024.0f) + k) * 10; Serial.println(value);}
Flash Blink
/*Orginial code by Mike Chamberssee details here:http://www.mikechambers.com/blog/2010/08/04/getting-started-with-flash-and-arduino/*/#define LED_PIN 13#define TOGGLE_LED_STATE 't'#define 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); }}
Pulse Width Modulation
"Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means."http://www.arduino.cc/en/Tutorial/PWM
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 Firmatatutorial here: http://blog.jvers.com/?tag=flash-as3glue-arduino-firmata-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
www.disturbmedia.com
www.arduino.cc