I am writing a C program to blink LED for Raspberry Pi. Its like (i) Blink LED (2) Stop blinking it.
Now while the LED is blinking, if I press 2 it should stop blinking. How to do it ?
If I include scanf
inside the code will stop blinking.
while(1)
{
printf("Enter a command \n 1.Blink Led\n 2. Stop blinking\n");
scanf("%d",&choice);
if(choice==1)
for (;;)
{
digitalWrite (LED, HIGH) ; // On
delay (500) ; // mS
digitalWrite (LED, LOW) ; // Off
delay (500) ;
// If i press 2 the led should stop blinking
}
else if(choice==2){
digitalWrite (LED, LOW) ;
}