I am trying to implement a small piece of code, and can basically be simplified to the following.
I have three different LEDs (say P0.0, P0.1 & P0.2). I have one push button that when pressed should first switch on the LED at P0.0. When pressed again should switch on P0.1 and so on. The LED is to remain on until the next push button is detected.
In the following test code, I am referring to each LED as a function. My idea was to increment a counter and depending on the count, light up a particular LED.
The output of this code is not what I expect. There is no transition between functions. Any suggestions on how I could restructure this code would be helpful.
I do not with to use interrupts for this code. Also, I have not included debouncing as I am targeting to be able to reproduce this code from scratch in 15 minutes.
else if ( SW1 != (0x00000002) ) //when pressed
{
delay(); //for debouncing
count++;
}
if (count == 1) {
IO0SET = (1<<0);
pattern1();
}
else if (count == 2) {
IO0SET = (1<<6);
pattern2();
}
else if (count == 3) {
IO0SET = (1<<7);
pattern3();
}
Is there a way in which I can break out immediately of the current function, instead of having to wait for it to finish?