zain kaleem
New Member
Ok, so here's my question. I just want to run a sequence of LEDs with delays between them in a if statement using push button. When the button is pressed LEDs lights up in a sequence else remain off. I have a while condition(while is used so that the sequence doesn't repeat) and switch denounce in the code which is working perfectly fine. But my problem is that when I press the button lets say for short amount of time(just a click) the whole sequence starts and then completes itself and then end the sequence.
I just want that when I press the button sequence starts but when I release the button (at anytime) it should stop working right away.
Have a look on my code. (I'm using MPLAB X IDE)
I just want that when I press the button sequence starts but when I release the button (at anytime) it should stop working right away.
Have a look on my code. (I'm using MPLAB X IDE)
C:
void main(void) {
TRISB7=0;
TRISB6=0;
TRISB5=0;
PORTBbits.RB7=0;
PORTBbits.RB6=0;
PORTBbits.RB5=0;
TRISA0=1;
PORTAbits.RA0=0;
ANSEL=0X00;
ANSELH=0X00;
while(1){
if(PORTAbits.RA0==0){
__delay_ms(70);
if(PORTAbits.RA0==0){
RB5=1;
__delay_ms(500);
RB6=1;
__delay_ms(700);
RB7=1;
__delay_ms(500);
RB7=0;
__delay_ms(700);
RB6=0;
RB5=0;
while(PORTAbits.RA0==0);
}
}
else{
RB5=0;
RB6=0;
RB7=0;
}
}
}