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
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
led1:A
led1:C
r1:1
r1:2