/**
 * Liest Poti auf dem Arduino aus und färbt das Rechteck danach
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup() 
{
  size(200, 200);
  String portName = Serial.list()[0]; // die Zahl 0 ist abhänig vom USB Device
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void draw(){}

        
void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if(inString != null) {
    inString = trim(inString);
    float inNumber = float(inString);
 
    fill(map(inNumber,0,1023,0,255));                
    rect(50, 50, 100, 100);
  }
}

/* Arduino Code

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

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

*/