`const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
Serial.println(brightness);
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}`
i tried the above code with my board
that code takes values from serial monitor and adjusts the brightness of the LED. but instead, the LED stucks at the HIGH state and brightness doesnt change with the input
also the value of brightness i print on serial monitor by Serial.println(brightness); it shows some garbage characters and symbols which are not readable. what should i do?