// 13 yg hijau pinBt[0]
// 14 yg kuning
const int pinBt[2] = {13, 14};
// pin led support PWM (15)
const int pinLed = 16; //15;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Serial.println("Hello, ESP32!");
pinMode(pinBt[0], INPUT); // atau INPUT_PULLUP
pinMode(pinBt[1], INPUT); // atau INPUT_PULLUP
pinMode(pinLed, OUTPUT);
// digitalWrite(pinBt[0], HIGH);
// digitalWrite(pinBt[1], HIGH);
}
int brightness = 0;
void loop() {
digitalWrite(pinBt[0], HIGH);
digitalWrite(pinBt[1], HIGH);
// put your main code here, to run repeatedly:
// delay(10); // this speeds up the simulation
if (digitalRead(pinBt[0]) == LOW){
brightness++;
Serial.println("kecerahan dinaikkan");
} else if ( digitalRead(pinBt[1]) == LOW ){
brightness--;
Serial.println("kecerahan diturunkan");
}
brightness = constrain(brightness, 0, 255);
analogWrite(pinLed, brightness);
// digitalWrite(pinBt[0], HIGH);
// digitalWrite(pinBt[1], HIGH);
delay(20);
}
// const int pinBt[2] = {2, 3};
// // pin 9 support PWM (Arduino Uno)
// const int pinLed = 9;
// void setup(){
// pinMode(pinBt[0], INPUT_PULLUP);
// pinMode(pinBt[1], INPUT_PULLUP);
// pinMode(pinLed, OUTPUT);
// digitalWrite(pinBt[0], HIGH);
// digitalWrite(pinBt[1], HIGH);
// }
// int brightness = 0;
// void loop(){
// if( digitalRead(pinBt[0]) == LOW ){
// brightness++;
// } else if( digitalRead(pinBt[1] == LOW )){
// brightness--;
// }
// int x = constrain(brightness, 0, 255);
// analogWrite(pinLed, x);
// delay(20);
// }