il codice non è mio

è comparso poco tempo fà sul forum... adegualo alle tue esigenze come meglio credi

Arduino
------------------------------------------------------------------------------------------------------------------------
int potpin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val = map(analogRead(potpin), 0, 1023, 0, 255);
Serial.println(val);
delay(50);
}
Processing
------------------------------------------------------------------------------------------------------------------------
import processing.serial.*;
Serial port;
float brightness = 0;
void setup()
{
size(500,500);
port = new Serial(this, "COM3", 9600);
port.bufferUntil('\n');
}
void draw()
{
background(0,0,brightness);
}
void serialEvent (Serial port)
{
brightness = float(port.readStringUntil('\n'));
}