Skip to content

Instantly share code, notes, and snippets.

void loop() {
potValue = analogRead(potPin); // membaca nilai potensiometer
Serial.println(potValue); // menampilkan nilai potensiometer pada Serial Monitor
delay(1000);
}
const int potPin = 34; // pin potensiometer
int potValue = 0; // variabel untuk menyimpan nilai potensiometer
void setup() {
Serial.begin(115200);
pinMode(potPin, INPUT); // inisialisasi pin sebagai input
delay(1000);
}
// Menggunakan 3 pin GPIO untuk PWM
const int ledPin1 = 5; // Nomor pin LED pertama
const int ledPin2 = 22; // Nomor pin LED kedua
const int ledPin3 = 23; // Nomor pin LED ketiga
// Mengatur properti PWM
const int freq = 5000; // Frekuensi PWM 5 kHz
const int resolution = 8; // Resolusi PWM 8-bit
void setup() {
void loop() {
// Mengatur kecerahan LED dengan mengubah nilai dutycycle (0-255)
for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
ledcWrite(0, dutyCycle); // Mengirimkan nilai dutycycle ke pin LED
Serial.println(dutyCycle); // Mencetak nilai dutyCycle ke Serial Monitor
delay(10); // Tunggu selama 10ms
}
delay(1000); // Tunggu selama 1 detik
}
void setup() {
Serial.begin(115200);
ledcAttachPin(ledPin, 0); // Menyambungkan PWM ke pin LED
ledcSetup(ledChannel, freq, resolution); // Kanal PWM 0, frekuensi 5kHz, resolusi 8-bit
}
// mengatur properti PWM
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
// jumlah pin LED
const int ledPin = 5; // 5 sesuai dengan GPIO5
// jumlah pin LED
const int ledPin = 5; // 5 sesuai dengan GPIO5
// mengatur properti PWM
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup() {
ledcAttachPin(ledPin, 0); // Menyambungkan PWM ke pin LED
ledcWrite(channel, dutycycle);
ledcAttachPin(GPIO, channel);