Alright, got it working. Many thanks, johnwasser! ![]()
For those who are interested, I am working with the Adafruit Neopixel LED strips. Through Processing, I am generating an image out of RGB-values. I use the Adafruit Neopixel Arduino library for driving the LEDs individually, and loop through the serial output from Processing in order to light all the LEDs. Besides that, I loop through a series of images, so the LED strip animates. It's pretty awesome!
The updated code (which includes the library from Adafruit: Arduino Library Use | Adafruit NeoPixel Überguide | Adafruit Learning System) might still need some extra work and fine-tuning, but it is alive and kicking!
Arduino code:
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
uint16_t pixelID = 0;
char inChar = '\0';
int inColor[3] = {0,0,0};
String serialBuffer = "";
int currentColor = 0;
void setup(){
 strip.begin();
 Serial.begin(9600);
 strip.show();
}
void loop(){
 while(Serial.available() > 0){
  inChar = Serial.read();
  if(currentColor < 3){
   if(inChar==','){
    inColor[currentColor] = serialBuffer.toInt();
    currentColor++;
    serialBuffer = "";
   }
   else {
    serialBuffer += (char)inChar;
   }
  }
  else { Â
   strip.setPixelColor(pixelID,strip.Color(inColor[0],inColor[1],inColor[2]));
   if(pixelID==59){
    strip.show();
    pixelID = 0;
   }
   else {
    pixelID++;
   }
   inColor[0] = 0;
   inColor[1] = 0;
   inColor[2] = 0;
   currentColor = 0;
  Â
  }
 }
}
Processing code (might still need some optimalization, work in progress):
import processing.serial.*;
Serial port;
String serial;
PImage[] images = new PImage[8];
String serialPrint = "";
String[] val = new String[8];
String intBetween = "";
int id = 0;
void setup() {
 size(10,6);
 port = new Serial(this, "COM9", 9600);
 port.clear();
 serial = port.readStringUntil(10);
 serial = null;
 for ( int i = 0; i< images.length; i++ )
 {
  images[i] = loadImage("gentle/1-gentle" + i + ".jpg" );
  images[i].loadPixels();
  val[i] = ""; // reset val[i]: remove null value
  for (int y = 0; y < height; y++) {
   for (int x = 0; x < width; x++) {
    int loc = x + y * width;
    val[i] += makeInt(red(images[i].pixels[loc]))+",";
    val[i] += makeInt(green(images[i].pixels[loc]))+",";
    val[i] += makeInt(blue(images[i].pixels[loc]))+",";Â
   }
  }
 }
}
void draw(){
 port.write(val[id]);
 id = (id==7) ? 0 : id + 1;
}
int makeInt(Float c){
 intBetween = c.toString();
 int iL = intBetween.length();
 return int(intBetween.substring(0,(iL-2)));
}