I'm currently working with the MSP430G2553, which is coded in C.
For some reason I seem to be awful at coding basic For
and While
loops, and I can't figure out how to make a While
loop take longer to complete after every iteration.
Basically, I have an LED blinking at 100ms on startup.
When I hold a button, I want to make the LED blink slower and slower the longer I hold the button.
When I let go, the LED should keep its slowed-down blinking rate.
Then, a second button will reset the LED blink-rate back to 100ms.
Right now, I'm able to slow down the LED blinking when I hold the button, but it does not keep going slower. Honestly, I'm not sure how to go about doing this so I made an account here and posted.
for(;;) //loop forever
{
if((P1IN & BIT3)==BIT3) //if button is not pressed
{
i = 0;
a = 4000; //At 10000, 4 cycles per second, or 250ms delay. 4000 cycles = 100ms or 10Hz delay.
P1OUT ^= BIT0 + BIT6; //two LEDs
while(i < a) //delays LED blinking until while-loop is complete.
{
i = i + 1;
}
}
else if((P1IN & BIT3)!=BIT3) //if button is pressed
{
i = 0;
a = 10000;
P1OUT ^= BIT0 + BIT6;
while(i < a) //delays LED blinking until while-loop is complete.
{
a = a + 2;
i = i + 1;
}
}
}