int led = 25;
int btn1 = 33;
int btn2 = 32;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("[email protected]");
pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
pinMode(led, OUTPUT);
}
void loop() {
int btn_status1 = digitalRead(btn1);
int btn_status2 = digitalRead(btn2);
// penggunaan operator logika AND &&
// if (digitalRead(33)== 0 && digitalRead(32)== 1)
// {digitalWrite(25, 0);}
// if (digitalRead(33)== 1 && digitalRead(32)== 0)
// {digitalWrite(25, 0);}
// if (digitalRead(33)== 1 && digitalRead(32)== 1)
// {digitalWrite(25,1);}
// else {digitalWrite(25, 0);}
// Serial.println(digitalRead(33));
// Serial.println(digitalRead(32));
// Serial.println(digitalRead(25));
// Penggunaan operator logika OR ||
// if (btn_status1 == HIGH || btn_status2 == HIGH) {digitalWrite(led, HIGH);}
// else {digitalWrite(led, LOW);}
// Serial.println(digitalRead(33));
// Serial.println(digitalRead(32));
// Serial.println(digitalRead(25));
// Penggunaan operator logika NOT !=
if (btn_status1 == HIGH != btn_status2 == HIGH) {digitalWrite(led, LOW);}
else {digitalWrite(led, HIGH);}
Serial.println(digitalRead(33));
Serial.println(digitalRead(32));
Serial.println(digitalRead(25));
}
Loading
esp32-devkit-v1
esp32-devkit-v1