/* Values MUST be 3 digits long, "0", must be "000", "15" must be "015" and so far.... Based on code created 2006 by David A. Mellis Modified 3/23/2020 by Marcelo Euler */ #define ledPin PA0 int brightness; char inInfo[3]; //array limited to 3 characters long void setup() { Serial.begin(115200); //not necessary for USB bootloader pinMode(ledPin,PWM); } void loop() { char ch; int indice=0; String TempString; while (Serial.available() > 0) { //loop while Serial is receiving ch=Serial.read(); if (ch !='\n'){ // check for "New Line" char inInfo[indice]= ch; //Store char in inInfo array at "indice" position, STARTING from zero indice=indice+1; //increase index character postion in char array } else { //end of information (\n = line feed) String TempString(inInfo); // char array converted in string (TempString) brightness = map(TempString.toInt(), 0, 255, 0, 65535); // convert string in to Int and adjust min and max values pwmWrite(ledPin, brightness); // Set the brightness of the LED: } } }