/*-----------------------------------------------------------------
 *           Serial communication with the Arduino 
 *   (For example - receiving data from Processing or Raspberry Pi)
 * Setup: Wire an LED from digital 6 thru 330 ohm resistor to gnd
 -----------------------------------------------------------------*/
 
int inData;        // variable for storing received serial data
int convertData;    // variable or storing data converted into integers
int ledPin = 6;     // variable for LED pin number

 void setup(){
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);        // set pin Mode for lighting LED
 }

void loop(){
    if (Serial.available() > 0){    // if serial data (RPi to Arduino)
       inData = Serial.read();      // read it, store in inData
       analogWrite(ledPin, inData); 
       delay(15);
     }
}