ESP32 LED Dimming Tutorial with Potentiometer | Control Brightness in Real Time | English Subtitle

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024
  • ESP32 LED Dimming Tutorial with Potentiometer | Control Brightness in Real Time | English Subtitle
    Code : code is on the comment below.
    Facebook : / doit20-104218935882053
    Please Subscribe my Channel. ThankYou!

ความคิดเห็น • 1

  • @doit.20
    @doit.20  4 หลายเดือนก่อน +1

    const int potPin = 34; // Analog input pin for potentiometer on ESP32
    const int ledPin = 5; // PWM enabled pin for LED on ESP32
    void configurePWM() {
    const int freq = 5000; // PWM frequency
    const int ledChannel = 0; // PWM channel
    const int resolution = 8; // PWM resolution (8 bits)
    // Configure LED PWM functionalities
    ledcSetup(ledChannel, freq, resolution);
    // Attach the channel to the GPIO to be controlled
    ledcAttachPin(ledPin, ledChannel);
    }
    void setup() {
    pinMode(potPin, INPUT); // Set the potentiometer pin as input
    configurePWM(); // Configure PWM for the LED
    }
    void loop() {
    int sensorValue = analogRead(potPin); // Read potentiometer value (0-4095 on ESP32)
    int brightness = map(sensorValue, 0, 4095, 0, 255); // Map potentiometer value to LED brightness (0-255)
    ledcWrite(0, brightness); // Set LED brightness using PWM on channel 0
    }