Processing arduino 2

From Medien Wiki
/**
 * Liesst Poti und Fotosensor aus und generiert zufällige Kreise 
 * Poti = inNumber[0] -> Rotwert
 * Fotosensor = inNumber[1] -> Alphawert 
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port
float[] inNumber;

void setup() 
{
  size(500, 500);
  smooth();
  background(255);
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void draw(){
  if(inNumber != null) {
    fill(map(inNumber[0],0,1023,0,255),random(255),random(255),map(inNumber[1],570,919,0,255));  // Werte 570 & 919 sind abhängig vom Fotosensor
    ellipse(random(width),random(height),40,40);
  }
}

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if(inString != null) {
    inString = trim(inString);
    inNumber = float(split(inString, ' ')); // der text werden durch " " zerteilt um an beide nummer zu kommen.. 
    }
}


/* Arduino Code

int potPin = 0;                       
int photoPin = 1;    
void setup() {
  Serial.begin(9600);    
}

void loop() {
  Serial.print(analogRead(potPin));
  Serial.print(" ");  
  Serial.print(analogRead(photoPin));  
  Serial.println();  
  delay(100);                          
}

*/