//=====================TUGAS MIKROKONTROLER====================//
//====MENYALAKAN & MEREDUPKAN LED MENGGUNAKAN POTENSIOMETER====//
//_____________________________________________________________//
//-------------NABILA HASNA RIZQI NURFADHILLAH-----------------//
//--------------------------TOLI 3B----------------------------//
//-------------------------2103411036--------------------------//
// adc input pot
// the number of the LED pin
const int ledPin = 2; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
//============================
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 12;
// variable for storing the potentiometer value
int potValue = 0;
float Tegangan;
// how bright the LED is
int brightness = 0;
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
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 GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin);
Tegangan = (3.3/4095)*potValue;
Serial.print("Potentiometer Value = ");Serial.print(potValue); Serial.print(" Teg= ");Serial.println(Tegangan);
int brightness = map(potValue, 0, 4095, 0, 255);
ledcWrite(ledChannel, brightness);
delay(100); // this speeds up the simulation
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
led1:A
led1:C
r1:1
r1:2
pot1:GND
pot1:SIG
pot1:VCC