Using Arduino and Processing together

Today I got up early and fooled around in Processing…for hours. I was playing with the Minim sound library, which I’d planned to use for my Intro to Computing Media project, an mp3 player. After sitting around for so long, I could how I was getting both noticeably older in age, but also wiser about Minim. Why sit around and program something completely different when I could put the two together? Well, my fear with combing my two projects, ICM and PhysComp, was that I’d skimp out on one or the other and not fully challenge myself. However, due to the MEX conference – to be blogged about soon! – my schedule is shorter than I’d like. Something’s gotta give. Sadly, it’ll have to be a little bit here and there on my projects.

Anyway, today, I worked on combining my Arduino code and my Processing code using serial output to play a song. Before discussing this, a little recap:

Create the code to turn on/off LEDs set at a threshold. Using the map() function and an if/else statement, I can now reliably turn off and on an LED as though it were a switch.
Here’s the code for the mapping and if/else statement part:

phoVal1 = analogRead(phoPin1);
  //map the photocell values and turn on the light
  phoVal1 = map(phoVal1, 0, 255, 255, 0);
  if (phoVal1>=0) {
    digitalWrite(pholed1,HIGH);
  }
  else{
    digitalWrite(pholed1,LOW);
  }

Here’s the code for the FSR:

FSRValue = analogRead(analogFSR); // read the left FSR value
  analogWrite(motorpin, FSRValue/4);

The next step was to combine this code with the Minim library in Processing. But first, write code in Processing! Here is where several hours with Minim came in handy. I was able to hobble together enough code to be able to play and pause a song. I haven’t yet created any arrays, for a media list, but that’s next, as well as the ability to move through the array. After that I sent the output in serial DEC to Processing. I just added this little bit of code:

if (xpos > 100){
 song.play();

After that, I was able to use the serial output from the FSR and Photocell to trigger the song.play(); function. I suppose, I could find a audio visualization program to tweak, so that I can make a pretty picture show when a song plays, assuming I play a song.

Next I’ll need to refine all the code, and plan out more of how I want the sensors to interact with the plants. And, I need to get some plants.

UPDATE: Code is not working as expected. Processing is just playing a song when the sketch is run. I need to figure this out some more.

One thought on “Using Arduino and Processing together”

Leave a Reply

Your email address will not be published.