motofreek
Junior Member level 2
Hi, I'm trying to write a code so that when 5 numbers (like 12345) are recieved in sequence an LED comes on. I'm using the code below and IT IS WORKING. However, if too many numbers are typed AFTER the numbers are entered from the keyboard, the program freezes up.
For eg. if I type 12345 the LED blinks once and I can repeat the action again.
But if I type 123456789, the LED blinks but I cannot do it again. The
program freezes.
while(true){
ch=getch();
switch(ch)
{
case '1':
if(getch()=='2'&&getch()=='3'&&getch()=='4'&&getch()=='5'){
output_high(PIN_B7);
delay_ms(2000);
output_low(PIN_B7);
goto jump;
}
break;
jump:
puts("prog restarting now");
Any ideas on how I can fix this ?
(I think it recieves too many characters in the buffer and gets confused)
For eg. if I type 12345 the LED blinks once and I can repeat the action again.
But if I type 123456789, the LED blinks but I cannot do it again. The
program freezes.
while(true){
ch=getch();
switch(ch)
{
case '1':
if(getch()=='2'&&getch()=='3'&&getch()=='4'&&getch()=='5'){
output_high(PIN_B7);
delay_ms(2000);
output_low(PIN_B7);
goto jump;
}
break;
jump:
puts("prog restarting now");
Any ideas on how I can fix this ?
(I think it recieves too many characters in the buffer and gets confused)