int inInt; // store data received from serial port
int ledPin = 11; // we will be using pin 11 for LED
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){ // scans and judges input
inInt = Serial.parseInt(); // reads an integer
Serial.print("received:"); // "received:"
Serial.println(inInt); // print out the received data
// use received integer and convert it to PWM duty cycle of ledPin port
analogWrite(ledPin, constrain(inInt, 0, 255));
}
}