Hi. I have stumbed upon something which is really confusing to me. (unless it's really basic)
I tried to implement a basic state machine. So there are three task and two of them have a single loop. I observe that when I use a loop the event occurs only once but once I unroll the loop it behaves ok. I tried to use a global variable with no effect.
int main() {
InitializeSystem();
while(1) {
state_table[curr_state]();
}
}
void Task1(){
for(int j=0;j<4;j++){ //blink only once
led1 = 1;
wait(1);
led1 = 0;
}
curr_state = BlinkTwoLed;//next state
}
I'd predict not only does it only flash once instead of four times, it *also* flashes for 4 seconds rather than 1 second (which should give a clue).
I think your problem is just a slip in your led flash code. In:
for(int j=0;j<4;j++) { //blink only once
led1 = 1;
wait(1);
led1 = 0;
}
you only have a delay after turning the led on. So on all but the last iteration of the loop, it'll turn off the led and then immediately turn it on again as it re-enters the loop; so you wont see it. So change it to:
Hi Dimiter,
I'd predict not only does it only flash once instead of four times, it *also* flashes for 4 seconds rather than 1 second (which should give a clue).
I think your problem is just a slip in your led flash code. In:
<<code>>
for(int j=0;j<4;j++) { //blink only once
led1 = 1;
wait(1);
led1 = 0;
}
<</code>>
you only have a delay after turning the led on. So on all but the last iteration of the loop, it'll turn off the led and then immediately turn it on again as it re-enters the loop; so you wont see it. So change it to:
<<code>>
for(int j=0;j<4;j++) {
led1 = 1;
wait(1);
led1 = 0;
wait(1);
}
<</code>>
and all should be fine!
Simon
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
Hi. I have stumbed upon something which is really confusing to me. (unless it's really basic)
I tried to implement a basic state machine. So there are three task and two of them have a single loop. I observe that when I use a loop the event occurs only once but once I unroll the loop it behaves ok. I tried to use a global variable with no effect.