3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

How to control LED's with Processing and Arduino

Step 2The Code

The Code
This was the hard part for me.  I have always been a hardware type rather than software type, so I turned to the internet.  the first place that I looked was the reference section of both Processing.org and Arduino.cc, a lot of time and consideration has gone into the development of these sites and I applaud the effort, it was worth it!  All the basic information that i needed was there but I was having a really hard time getting it all to work.  So i turned to this tutorial to set me straight.  Francesco has put together a great tutorial about Processing serial communication and the Arduino.

Once I got it all to work, it was actually very simple.  Basically the Processing code will be setup like this:

import processing.serial.*;

Serial myPort;

void setup(){ 
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[*X*], 9600);
  myPort.buffer(1);
  size(400, 400);

void draw(){
 //some code goes here
}

When setting up your code make sure that your Arduino is connected to your serial port.  This is important because the code is attempting to point to the specific arduino that you are using.  Run your code and look at the list that will be displayed at the bottom of your Processing window and then change the variable in your code that i have indicated by the *X* to the number of the port that your arduino is connected to.  Mine was the third on the list so I put 2 in place of the *X*.  Keep in mind that the list is displayed as array entries, this means that the first position is indicated as 0 not 1.

The Arduino code is even simpler to setup:

void setup(){
 Serial.begin(9600);
}

I have posted the completed codes for you to take and modify and play with.  The arduino is saved as pdxMap.pde and the processing code is saved as serialLEDTest.pde



« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
1
Author:SammyDestruction