#define LED1 4
#define switch1 5
#define LED2 16
#define switch2 17
void setup()
{
// put your setup code here, to run once:
pinMode(LED1, OUTPUT);
pinMode(switch1, INPUT_PULLUP);
pinMode(LED2, OUTPUT);
pinMode(switch2, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop()
{
kedip();
tekan();
}
void kedip()
{
if ( digitalRead(switch1) == LOW)
{
// put your main code here, to run repeatedly:
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
Serial.println("Lampu 1 ON"); // wait for a second
digitalWrite(LED1, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
delay(10); // this speeds up the simulation
Serial.println("Lampu 1 Off");
}
else
{
digitalWrite(LED1, LOW);
}
}
void tekan()
{
if (digitalRead(switch2) == LOW)
{
// put your main code here, to run repeatedly:
digitalWrite(LED2, HIGH);
Serial.println("Lampu 2 ON");
}
else
{
digitalWrite(LED2, LOW);
}
}