View
222
Download
0
Category
Preview:
Citation preview
Processing
TYWu
Where can I download?
• http://processing.org/download/
2.0b9Windows 32-bit
How to Install
• You'll have a .zip file.
• Double-click it, and drag the folder inside to a location on your hard disk.
• It could be Program Files or simply the desktop, but the important thing is for the processing folder to be pulled out of that .zip file.
• Then double-click processing.exe to start.
Getting Started
• Windows RUN STOP
Getting Started
• Function– ellipse(50, 50, 80, 80);
• This line of code means "draw an ellipse, with the center 50 pixels over from the left and 50 pixels down from the top, with a width and height of 80 pixels." Click the Run button, which looks like this:
Getting Started
• Examplevoid setup() {
size(480, 120); //Open a Display Window
}
void draw() {
if (mousePressed) fill(0);
else fill(255);
ellipse(mouseX, mouseY, 80, 80);
}
Getting Started
• Result
Communication Between Arduino and Processing
• By RS232
Serial.begin(9600);:Char Value;:Serial.write(Value);:
import processing.serial.*;Serial serial; :serial = new Serial(this, "COM20", 9600);sensorValue = serial.read();:
Communication Between Arduino and Processing
• Step 1– Run Arduino
• Step 2– Run Processing
Communication Between Arduino and Processing
• Example of Arduino
int ultraAn = 0;
int val = 0;
char dist = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(ultraAn);
dist = (val*2.1)/3;
Serial.write(dist); //Unit = 3cm
delay (1000); // delays 1 secconds in between readings
}
Communication Between Arduino and Processing
• Example of Processingimport processing.serial.*;Serial serial; int sensorValue;void setup() {size(700, 200);serial = new Serial(this, "COM20", 9600);}void draw() { if ( serial.available() > 0) { sensorValue = serial.read(); println(sensorValue); background(255); fill(0,255,0); //Green rect(10, 95, sensorValue*3, 10); } }
Communication Between Arduino and Processing
• Result
Function
• rect(a, b, c, d)
• a (float): x-coordinate of the rectangle by default
• b (float): y-coordinate of the rectangle by default
• c (float): width of the rectangle by default
• d (float): height of the rectangle by default
References
• http://processing.org/learning/gettingstarted/
• http://www.instructables.com/id/Arduino-to-Processing-Serial-Communication-withou/
• http://www.processing.org/reference/rect_.html
• http://coopermaa2nd.blogspot.tw/2011/03/processing-arduino.html
Recommended