// the number of the LED pin
const int ledPin = 21; // 5 corresponds to GPI21
// setting PWM properties
const int freq = 5000; //Freq off PWM
const int ledChannel = 0; // Led chanel selected 0-15
const int resolution = 8; // Resolution - 1-20 bits
// The number of slide switch pin & aux to store value
const int bot = 12;
int b = 0;
// the number of Pot pin & aux store value
int Pot = 4;
int p = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPI0 to be controlled
ledcAttachPin(ledPin, ledChannel);
pinMode(Pot, INPUT);
pinMode(bot, INPUT);
Serial.println("Hello, ESP32!");
}
void loop()
{
/*
// increase the LED brightness
for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++)
{
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(50);
} // decrease the LED brightness
ledcWrite(ledChannel, 0);
delay(2000);
// decrease the LED brightness
for (int dutyCycle = 255; dutyCycle >= 255; dutyCycle−−)
{
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(10);
}
delay(1000)
*/
p = analogRead(Pot);
delay(25);
Serial.print("Pot");Serial.print(p);
int conv = map(p, 0, 4095, 0, 225);
Serial.print("conv:");Serial.println(conv);
ledcWrite(ledChannel, conv);
}