void setup() {
Serial.begin(9600);
Serial.println("let's start serial monitor");
}
void loop() {
// Assumes a string in from the serial port like so:
// s ledNumber, brightness \n
// for example: "s5,200\n":
int ledNumber = 0;
int brightness = 0;
if (Serial.find("s")) {
ledNumber = Serial.parseInt(); // parses numeric characters before the comma
brightness = Serial.parseInt();// parses numeric characters after the comma
// print the results back to the sender:
Serial.print("LED number: " );
Serial.print(ledNumber);
Serial.print(" at ");
Serial.println(brightness);
// set the LED:
analogWrite(ledNumber, brightness);
}
}