const int potPinRed = 34; // Pin untuk potensiometer merah
const int potPinGreen = 35; // Pin untuk potensiometer hijau
const int potPinBlue = 36; // Pin untuk potensiometer biru
const int potPinYellow = 32;
const int ledPinRed = 19; // Pin untuk LED merah
const int ledPinGreen = 18; // Pin untuk LED hijau
const int ledPinBlue = 5; // Pin untuk LED biru
const int ledPinYellow = 21;
void setup() {
Serial.begin(9600);
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinBlue, OUTPUT);
pinMode(ledPinYellow, OUTPUT);
}
void loop() {
// Baca nilai potensiometer
int potValueRed = analogRead(potPinRed);
int potValueGreen = analogRead(potPinGreen);
int potValueBlue = analogRead(potPinBlue);
int potValueYellow = analogRead(potPinYellow);
// Konversi nilai potensiometer ke rentang 0-255
int brightnessRed = map(potValueRed, 0, 4095, 0, 255);
int brightnessGreen = map(potValueGreen, 0, 4095, 0, 255);
int brightnessBlue = map(potValueBlue, 0, 4095, 0, 255);
int brightnessYellow = map(potValueYellow, 0, 4095, 0, 255);
// Atur intensitas warna RGB
analogWrite(ledPinRed, brightnessRed);
analogWrite(ledPinGreen, brightnessGreen);
analogWrite(ledPinBlue, brightnessBlue);
analogWrite(ledPinYellow, brightnessYellow);
Serial.print("warna merah=");
Serial.println(brightnessRed);
Serial.print("warna hijau=");
Serial.println(brightnessGreen);
Serial.print("warna biru=");
Serial.println(brightnessBlue);
Serial.print("warna kuning=");
Serial.println(potValueYellow);
delay(1000);
// Delay kecil untuk mengurangi kecepatan pembacaan potensiometer
}
Loading
esp32-devkit-v1
esp32-devkit-v1