Processing:
What is there in the Processing software?
Processing is a language and a development environment which came into existance in 2001.It is created by Ben fry and Casey Reas at MIT media labs It is open and free to download development environment that can run on windows,linux and Mac.It is used by artists,designers,researchers and hobbists to create amazing visual arts and softwares.
It has something for everyone no matter which domain of programming you fall into,if you are a android developer you can develop apps on it,if you work with core java you will find that in this too,similarly if you work in python there is also a python mode which has been added recently.Similarly if you want to work with OpenCV or want to create web servers or want to play with audio files or create GUI and interect with hardware like arduino or kinect,it has it all. whats brillient about this language is it has its own syntax and style but also gives you ability to make use of methods of some other specific domains like javascript,java,scala,actionscript, python,android, etc
Many people don't know but Arduino IDE has come out from processing. Thats why there is a striking similarity between the two IDE.
This is one of the most versatile software environment that i have seen so far. It also gives you the ability to export your source code as an application that can run on Linux,Windows and Mac. This is a great feature for creating applications for an end user.
Downloading and installing Processing:
Processing is free to download. You can download it for your operating system from the following link download processing
After you download the zip file you will need to extract it. After you extact it you will find a folder that that will have the following content
You need not wait for any installation process to occur just double click on the processing icon and you are ready to write your first program.
When you will run it for the firsttime. It will create a procesing folder in your Libraries/Documents on a windows machine.
Your source codes are called sketches in processing and all your source codes will be saved in a folder within this folder . The name of the subfolder will be same as that of your source code.
Now you are all set to write your first code.
Arduino Code: Upload this code to Arduino board
Processing Code:
For more info about the methods and API you can visit processing website orProcessing forum
Example: Replicating a graphics in processing
I have a picture that i will replicate with a processing code. The picture is as below and is taken from http://www.clker.com/clipart-25665.html
// This code is written by Deepankar Maithani //IMPORTANT //The top left corner of the processing window is considered as (0,0) coordinate all the coordinate values are set with respect to that. void setup() { size(600,600); // size of processing window background(255);// set color of background to white noFill();// upcoming figures will only have boundries strokeWeight(10); // width of boundries ellipse(150,300,150,150);//back tyre ellipse(150,300,30,30);// back smaller inner circle ellipse(390,300,150,150);//Front tyre ellipse(390,300,20,20);//front smaller inner circle ellipse(260,320,50,50);// paddle axle arc(150, 300, 180, 180, 4.1015, 5.8468, OPEN);// back mudguard arc(390, 300, 185, 185, 4.1887, 5.8468, OPEN);// front mudguard line(235,262,340,220);// connecting line back to front mudguard strokeWeight(10.0);width graphics strokeJoin(ROUND);// the characteristic of join beginShape(); vertex(150, 285);// chain upper part. vertex(260,295);// endShape(); line(260,345,150,315);//chain lower part. done without the vertex strokeWeight(10); beginShape(); vertex(390, 290);// draws handle bar vertex(320,150); vertex(300,165); vertex(280,160); endShape(); line(250,250,220,200); beginShape();// draws rider's seat vertex(195,200); vertex(240,200); vertex(190,180); vertex(195,198); endShape(); } void draw() { // empty cause it is just a static graphics }
NOTE: use ellipse command to draw the back tyre if you want exactly the same picture i like it this way
OUTPUT
Example 2 Displaying Sensor Value from arduino in Processing Window
Arduino Code: Upload this code to Arduino board
//This code written by Deepankar Maithani const int pot=A0;// Connect the middle pin of pot to this pin int reading;// variable for storing the pot values void setup() { //initialize serial communications at a 9600 baud rate Serial.begin(9600); } void loop() { reading=analogRead(pot);// reading the analog value Serial.println(reading);// printing it on serial this line sends the data to processing delay(1000);// stop for 1s }
Processing Code:
// This software is written by Deepankar Maithani import processing.serial.*; // this library handles the serial talk Serial myPort; // Create object from Serial class String data="" ; // empty string to gather the pot values PFont myFont; // object from the font class void setup()// this runs just once { size(500,500); // size of processing window background(0);// setting background color to black myPort = new Serial(this, "COM12", 9600);// giving parameters to object of serial class,put the com to which your arduino is connected and the baud rate myPort.bufferUntil('\n');// gathers data till new line character myFont=loadFont("Arial-Black-48.vlw");// font type see the data folder of your sketch textFont(myFont,70);// font size } void draw() { background(0);//refreshing background everytime the draw runs textAlign(CENTER);// alighn text to the centre of coordinates fill(255);// fill white color to text text(data,350,155);// display the data at 350,155 coordinate textSize(40);// size of text fill(#4B5DCE);// fillinf blue color on the text text("Pot. Reading",155,150); noFill();the upcoming rect will not have anything inside stroke(#4B5DCE);// color of boader of rectangle rect(5,100,400,80); rectangle } void serialEvent(Serial myPort)// whenever serial event happens it runs { data=myPort.readStringUntil('\n'); gathering data from pot in a variable }
Demo of above softwares in action
Arduino to Processing by Deepankar Maithani is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
No comments:
Post a Comment