mershi
Newbie level 2
I am writing a code in mikroc,
Can someone explain as to why it is difficult to break out of loop.. if the loop contains a high delay_ms()?
say if i have a button.. and if i press the button once.. it should break out of the loop..
say for example i have a code:
this causes problem.. sometimes it works but sometimes i need to hold the button for 2 seconds and release to break out of the loop..
this problem does not happen if i have a delay of.. say.. delay_ms(10); (with smaller delay_ms, i can just push the button once and it breaks out of the loop everytime)
What should i do to solve the issue? and still retaining a delay_ms(300) or higher..
Can someone explain as to why it is difficult to break out of loop.. if the loop contains a high delay_ms()?
say if i have a button.. and if i press the button once.. it should break out of the loop..
say for example i have a code:
HTML:
while(btn1==1){
PORTC.f0 ==1;
delay_ms(300);
PORTC.f0 ==0;
delay_ms(300);
if (Button(&PORTA, 1, 1, 1)) {
btn1 = 0;
previous2 = 1;
}
}
if (previous2 && Button(&PORTA, 1, 1, 0)) {
PORTC.f0 ==0;
previous2 = 0;
}
this causes problem.. sometimes it works but sometimes i need to hold the button for 2 seconds and release to break out of the loop..
this problem does not happen if i have a delay of.. say.. delay_ms(10); (with smaller delay_ms, i can just push the button once and it breaks out of the loop everytime)
What should i do to solve the issue? and still retaining a delay_ms(300) or higher..
Last edited: