I want to configure my button and configure LED blink speed so that when I press the button the first time the LEDs blink slower. When I press a second time the LEDs blink more slowly still, When I press a third time and LEDs blink the slowest.
After all when I press the button a fourth time I want to LEDs off (i.e. not blink until I press the button). I thought I can do this with mod operator (a % 3 == 0
???)
Here is my code after update :
unsigned int rate = 1000000;
int NUM_STATES = 4 ;
unsigned int counter=1;
for(;;)
{
if( buttonPressed() )
{
rate += 2000000;
counter++;
}
if(counter % 4 == 0)
{
rate = 0;
}
flashSequence(rate);
}
}
int buttonPressed(void)
{
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
return 1;
else
return 0;
}
void flashSequence (int rating)
{
if (rating == 0)
GPIO_ResetBits(GPIOD,
GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
else
{
/* PD12 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_12);
/* Insert delay */
Delay(rating);
/* PD13 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_13);
/* Insert delay */
Delay(rating);
/* PD14 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_14);
/* Insert delay */
Delay(rating);
/* PD15 to be toggled */
GPIO_SetBits(GPIOD, GPIO_Pin_15);
/* Insert delay */
Delay(rating);
GPIO_ResetBits(GPIOD,
GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
Delay(rating);
}
}