I have been having troubles doing the above topic and i will love if you guys can help me out.
I started programming few weeks back. I want to design a switch in which when the push button is pressed, my fan will ON, and when i need to turn it of, i press the same push button. so here is my code below.
#define OUTPUT 0
#define INPUT 1
#define ON 1
#define OFF 0
#define SWITCH1 PORTC.F0
#define LED1 PORTD.F0
void main() {
TRISC=INPUT; TRISD=OUTPUT;
PORTC=OFF; PORTD=OFF;
while(1){
if(SWITCH1==ON){
delay_ms(100);
if(SWITCH1==ON){
LED1=ON;
delay_ms(100);
} }
if(SWITCH1==ON)
{
delay_ms(100);
if(SWITCH1==ON){
LED1=OFF;
delay_ms(100);
} }
}
I will love to hear response from my fellow programmers. Thanks