const int ledPin = 14; // GPIO pin connected to the LED
const int pwmChannel = 0; // PWM channel
const int pwmResolution = 8; // PWM resolution (8 bits)
char serialInput; // Variable to store serial input
int delay1=1000;
int brightness = 0; // LED brightness
void setup() {
pinMode(ledPin, OUTPUT);
ledcSetup(pwmChannel, 5000, pwmResolution); // Configure PWM channel: frequency=5000Hz, resolution=8 bits
Serial.begin(115200); // Initialize serial communication
delay(delay1);
Serial.println("Hello User");
delay(delay1);
Serial.println("Initailizing.");
delay(delay1);
Serial.println("Initailizing..");
delay(delay1);
Serial.println("Initailizing...");
delay(delay1);
ledcAttachPin(ledPin, pwmChannel); // Attach PWM channel to LED pin
Serial.println("Press '+' to increase the light intensity ");
Serial.println("Press '-' to decrease the light intensity ");
}
void loop() {
if (Serial.available() > 0) {
serialInput = Serial.read(); // Read serial input
if (serialInput == '+') { // Increase brightness
if (brightness < 255) {
brightness++;
ledcWrite(pwmChannel, brightness); // Increase LED brightness
Serial.print("Brightness increased to: ");
Serial.println(brightness);
} else {
Serial.println("Maximum brightness reached.");
}
} else if (serialInput == '-') { // Decrease brightness
if (brightness > 0) {
brightness--;
ledcWrite(pwmChannel, brightness); // Decrease LED brightness
Serial.print("Brightness decreased to: ");
Serial.println(brightness);
} else {
Serial.println("Minimum brightness reached.");
}
}
}
delay(100); // Delay for stability
}
//what does 255 represent
//reseloution and pwd
//whats happening in the microcontroller as the brightness increase
//WHat is the function of the PWM