// Name: Cheung Tsz Hin
// No.: 250345657
// Class: EG114403/1C
// Program: 1C_Ex6_Q3_CheungTszHin.ino
// Program: Ex6C_Analog_Output-E_v2.ino
// Wokwi: https://wokwi.com/projects/401206045567453185
#define LED_Out_Pin 25 //Define LED_Out_Pin pins is 25
#define SW_In_Pin 15 //Define SW_In_Pin pins is 25
int VRvalue; // Set variables VRvalue
void setup() {
Serial.begin(115200);
// Set pins
pinMode(SW_In_Pin, INPUT_PULLUP); //This pin is set to Input and the default is pullup.
ledcAttach(LED_Out_Pin, 12000, 12); // Frequency 12 kHz, Resolution 12-bit (Value range 0-4095)
}
void loop() {
VRvalue = analogRead(VR_In_Pin); // Reading the value of the variable resistor
Serial.print("Raw Sensor reading: "); //showding the value
Serial.println(VRvalue);
ledcWrite(LED_Out_Pin, VRvalue);//Controlling LED brightness
delay(10);
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4