Pages

Friday, 11 January 2019

ESP32-CONTROLLING LED USING SWITCH

ESP32-CONTROLLING LED USING SWITCH


Aim:
Controlling LED using a Switch
Objective:
Understanding the working of switch. Turn ON the led when switch is pressed and Turn off when it is released
Connections:
Pin Mapping:
Switch
I012
LED
I04

Program:
void setup() {
pinMode(4, OUTPUT);//Initialize the output pin 
pinMode(12, INPUT);//Switch is connected to pin 12
Serial.begin(9600);
}
 
// the loop function runs over and over again forever
void loop() { 
if (digitalRead(12)==HIGH)
{
digitalWrite(4, HIGH);// Turn the LED on
delay(1000);   // Wait for a second.
digitalWrite(4, LOW);  // Turn OFF LED
delay(1000); // Wait for a second.
}
}

No comments:

Post a Comment