// LED is connected to GPIO 2
const int ledPin = 2;
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potentiometerPin = 34;
// variable for storing the potentiometer value
int potentiometerValue = 0;
float potentiometer_Vout = 3.3;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(potentiometerPin, INPUT);
Serial.println("Hello, Ade Satria Hardinata!");
}
void loop() {
potentiometerValue = analogRead(potentiometerPin); // Reading potentiometer value
// Description: Map data from one range to another.
// Function prototype: map(value, fromLow, fromHigh, toLow, toHigh)
int dutyCycle = map(potentiometerValue, 0, 4095, 0, 254);
Serial.print("Duty Cycle: ");
Serial.println(dutyCycle);
// changing the LED brightness with PWM
analogWrite(ledPin, dutyCycle);
delay(3);
}