In this tutorial We are going to use a single push button. When it is first pressed LED will be turned ON. When it is pressed next LED will be turned off.
How to turn on and off LED with 2 push buttons?
The i/o connections are,
void main() {
P0_0 = 0;
P1_0 = 0;
while(1) {
if(P0_0 == 1) {
while(P0_0 != 0);
P1_0 = ~ P1_0;
}
}
}
P1_0 for output i.e LED.
How to turn on and off LED with 2 push buttons?
Cheers!!!!
-> Let Us Embed <-
How to turn on and off LED with 2 push buttons?
Hardware Connection:
Input
P0_0 to Gnd, +5 to SW1Output
P1_0 to LEDProgram:
#include<at89x52.h>void main() {
P0_0 = 0;
P1_0 = 0;
while(1) {
if(P0_0 == 1) {
while(P0_0 != 0);
P1_0 = ~ P1_0;
}
}
}
Explanation:
P0_0 for input i.e push button.P1_0 for output i.e LED.
Inside the super loop,
if P0_0 is equal to 0 aka push button is pressed toggle the led state. So if the LED is Off then turn On the LED and vice versa.while(P0_0 != 0)
It is added for debounce. This is a software debounce it simply means waiting for push button to release.How to turn on and off LED with 2 push buttons?
Working Video:
Will be available soon!! :)Cheers!!!!
-> Let Us Embed <-